a ssh loader wrote by bash shell script to let ssh accept command line password
APACHE-2.0 License
sshpass.sh is a bash shell script for ssh to accept command line password.
the goal is to enable the automation for the very 1st time of linux server setup(maybe just save pub key to .ssh/authorized_keys).
sshpass.sh project home page - https://github.com/huan/sshpass.sh
Yes, everyone knows we should use the private/public key pairs when we manage linux server.
But, how about the very 1st time we setup the server? the worse, how about lots of fresh servers without ssh key set?
This is why I need sshpass, and I want a simplest way to do this.
echo "password123456" | ./sshpass.sh ssh buntu@localhost 'whoami'
ubuntu
Eric Pruitt Says: Januar 20th, 2013 at 10:30
Hello, I have modified your code so that password does not have to be written to a temporary file:
The technique shown here for using SSH in a script with password authentication but without a password prompt has been tested on recent versions of Ubuntu and CentOS, so should work for most Linux distributions. It uses a combination of (a) setsid to run ssh in a new session and (b) setting the SSH_ASKPASS environment variable. If SSH_ASKPASS is set to the path of a Bash script, OpenSSH will run the script and take the result as the password without a prompt - but only under somewhat contrived circumstances.
Connect To Remote SSH Server You can connect to the remote ssh server called server1 and use pty for communication between socat and ssh, makes it ssh's controlling tty (ctty), and makes this pty the owner of a new process group (setsid), so ssh accepts the password from socat.
$ (sleep 5; echo YOURSSHPASSWORDHERE; sleep 5; echo date; sleep 1) |socat - EXEC:'ssh -l userName server1.nixcraft.net.in',pty,setsid,ctty
Added handling of interrupt signal (Ctrl+C) for proper termination of the script and its child processes by @mixalbl4-127
Initial version
Huan Li (LinkedIn), Microsoft Regional Director, [email protected]