Reputation: 18918
So I have a script that ssh into another computer. Since I use it often, I was wondering if I could have the script automatically enter in the password prompted by ssh, or in any other way bypass copy-pasting the password every single time I run the script?
Upvotes: 1
Views: 1199
Reputation: 141790
It may be better to have a passphrase-less private key on the client side, paired with a public key in the server-side authorized_keys file with a specific command that gets run.
For example, having the following in .ssh/authorized_keys2
for the given user on the remote host:
command="date" ssh-rsa AAAAB3NzaC1yc2EAAAABIw[...]Q== Comment for passphraseless key
Will only ever run date
when you connect using that key:
[localhost] % ssh -i /path/to/id user@remotehost
Sun 20 Nov 2011 20:29:59 EST
Connection to remotehost closed.
Upvotes: 3
Reputation: 301117
Better setup up ssh keys with empty passphrase than putting your password in a script.
https://wiki.archlinux.org/index.php/SSH_Keys
Upvotes: 3