Solution1:use sshpass
#~/bin/myssh.sh
sshpass -p a1234b ssh myname@somehost
You can install by
# Ubuntu/Debian
$ sudo apt-get install sshpass
# Red Hat/Fedora/CentOS
$ sudo yum install sshpass
# Arch Linux
$ sudo pacman -S sshpass
#OS X
brew install https://raw.githubusercontent.com/kadwanev/bigboybrew/master/Library/Formula/sshpass.rb
or download the Source Code from here, then
tar xvzf sshpass-1.08.tar.gz
cd sshpass-1.08.tar.gz
./configure
sudo make install
Solution2:Set SSH passwordless login
Let's say you need to SSH into bbb@2.2.2.2(Remote server B)
with the password 2b2b2b
from aaa@1.1.1.1(Client server A)
.
Generate the public key(.ssh/id_rsa.pub)
and private key(.ssh/id_rsa)
in A with the following commands
ssh-keygen -t rsa
[Press enter key]
[Press enter key]
[Press enter key]
Use the following command to distribute the generated public key(.ssh/id_rsa.pub)
to server B under bbb‘s .ssh directory as a file name authorized_keys
ssh-copy-id bbb@2.2.2.2
You need to enter a password for the first ssh login, and it will be logged in automatically in the future, no need to enter it again!
ssh bbb@2.2.2.2 [Enter]
2b2b2b
And then your script can be
#~/bin/myssh.sh
ssh myname@somehost