marceloNYC
asked on
Getting my shell script to authenticate
Dear experts,
I am trying to run a script that has to ssh using my account and is not letting me.
I am getting:
me@host's password:
Permission denied (publickey,password).
The script is:
##!/bin/bash
username="me"
HOSTS=( linux1 linux2 )
echo "Array is ${HOSTS[@]}"
for HOSTNAME in "${HOSTS[@]}"; do
echo "Rebooting $HOSTNAME..."
ssh $username@$HOSTNAME "sudo reboot"
sleep 900
done
I need to get the ssh key I take to work when running the script.
I am trying to run a script that has to ssh using my account and is not letting me.
I am getting:
me@host's password:
Permission denied (publickey,password).
The script is:
##!/bin/bash
username="me"
HOSTS=( linux1 linux2 )
echo "Array is ${HOSTS[@]}"
for HOSTNAME in "${HOSTS[@]}"; do
echo "Rebooting $HOSTNAME..."
ssh $username@$HOSTNAME "sudo reboot"
sleep 900
done
I need to get the ssh key I take to work when running the script.
ASKER
Yes I do have an SSH key. I have a windows WS and can set up the SSH in a linux box. I think will do that.
Is that it will take?
Is that it will take?
I am not sure what you are saying. If you have SSH key authentication setup already, then you can use it without issue.
Please be more precise.
Please be more precise.
Do you have a .ssh/id*.pub and/or identity.pub files whose contents you added to the authorized_keys and authorized_keys2 in the remote folder of $username on $hostname? Note if you use a passphrase you need to....
Are you typing in the password?
The other option is to use expect to handle the authentication.
Are you typing in the password?
The other option is to use expect to handle the authentication.
ASKER
Hi,
Sorry I did not write my last comment well.
My workstation is windows 7 using MobaXterm.
I could also connect to a Linux server I have. I m going to copy my ssh key to it.
When I connect to this devices I have passphrase (Authenticating with public key "rsa-key-201xxx5"
Passphrase for key "rsa-key-201xxx5"). I usually just enter my user name and I am all set. No need for the password.
Should I try from the Linux server?
Sorry I did not write my last comment well.
My workstation is windows 7 using MobaXterm.
I could also connect to a Linux server I have. I m going to copy my ssh key to it.
When I connect to this devices I have passphrase (Authenticating with public key "rsa-key-201xxx5"
Passphrase for key "rsa-key-201xxx5"). I usually just enter my user name and I am all set. No need for the password.
Should I try from the Linux server?
I am still unsure of your problem.
You need to setup ssh keys (without passphrase) between the system you are running the script on and the systems you are trying to reboot. Once you can connect to them without a password/passphrase, you can run the script without issue.
You need to setup ssh keys (without passphrase) between the system you are running the script on and the systems you are trying to reboot. Once you can connect to them without a password/passphrase, you can run the script without issue.
ASKER
The script will not work until it authentication is fix.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Clear,
Will do thank you!
Will do thank you!
I think the points should be split.please advise whether you wish the question reopened.
ASKER
Thank you,
I will
I will
If you have one already it is usually stored in ~/.ssh/ directory.