3

I'm trying to SSH to a server on startup with a .sh script, but that will require me to enter the password for the account on the server that I'm SSHing to. I did some RTFMing, and I see in "-o" that it has "PasswordAuthentication" but I'm not sure how or if I could use that option. As this will be in a shell script, obviously I'd like to have the password in that file, or in any case not have to enter in the password manually every time the script runs.

4
  • 2
    This still is valid: askubuntu.com/questions/46930/… :)
    – Rinzwind
    Dec 1, 2012 at 9:38
  • How can I make ssh-copy-id use a port other than 22? I tried it with -p but I get: Bad port 'umask 077; test -d ~/.ssh || mkdir ~/.ssh ; cat >> ~/.ssh/authorized_keys'
    – Eva
    Dec 1, 2012 at 9:55
  • Create a new question for the TCP-port thing.
    – jippie
    Dec 1, 2012 at 10:07
  • askubuntu.com/questions/224190/…
    – Eva
    Dec 1, 2012 at 10:18

3 Answers 3

2

I'm on my phone now so I can't give you a detailed answer. The proper solution here in my opinion is to use key based authentication. Basically you use ssh-keygen (I think) to generate a public/private key pair. Since you need script access, enter a blank password when prompted. Then, follow the relevant man pages to install the public key on the server and install the private key in its proper place.

Now you should be able to log in to that server securely and without a password. Note that by securely I mean as long as your user account isn't compromised.

1

I would suggest that you use ssh-keygen to generate an ssh key and use that to login to your remote ssh server.

The procedure is explained here.

0

This thread on ServerFault suggests two ways, one with sshpass:

sudo apt-get install sshpass
sshpass -p your_password ssh user@hostname

and one with expect:

#!/usr/bin/expect -f
#  ./ssh.exp password 192.168.1.11 id
set pass [lrange $argv 0 0]
set server [lrange $argv 1 1]
set name [lrange $argv 2 2]

spawn ssh $name@$server
match_max 100000
expect "*?assword:*"
send -- "$pass\r"
send -- "\r"
interact

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.