Link to home
Start Free TrialLog in
Avatar of marceloNYC
marceloNYCFlag for United States of America

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.
Avatar of Steven Vona
Steven Vona
Flag of United States of America image

Do you have an SSH key or do you need to make a new one?

If you have one already it is usually stored in ~/.ssh/ directory.
Avatar of marceloNYC

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?
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.
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.
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?
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.
The script will not work until it authentication is fix.
ASKER CERTIFIED SOLUTION
Avatar of arnold
arnold
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Clear,

Will do thank you!
I think the points should be split.please advise whether you wish the question reopened.
Thank you,

I will