See ChinaUnix above a users post, like in linux when to use ssh login without a password each time, they can not use the key way.
Web search for a moment, there are users expect to write with an automatic logon script, but after I tried, but found that can not be used.
Then to see people that use sshpass can solve the problem. So, if you write a script. Script written in simple, do not consider security issues. To use this script to install sshpass the software.
sshlogin.sh:
#! / Bin / bash
#================================================= ==============================
FILENAME:
Sshlogin.sh
DESCRIPTION:
Script to use user and password from config file to login remote
Ssh server.
This script needs 1 argument to login the remote ssh server:
Ipaddr = IP Addreess of remote ssh server.
For example:
#. / Sshlogin.sh 192.168.0.1
You need to create a config file (pass.dat) with entries like:
Server1 | user | password
Server2 | user | password
REVISION (MM / DD / YYYY):
07/01/2009 Shengkui Leng (shengkui.leng @ advantech.com.cn)
- Initial version
#================================================= ==============================
#------------------------------------------------- -----------------------------
NAME:
Print_usage
DESCRIPTION:
Print usage information
PARAMETERS:
$ 1 - Program name
RETURNS:
None
#------------------------------------------------- -----------------------------
print_usage ()
(
echo “Usage: $ 1”
exit 1
)
[$ #-Eq 1] | | print_usage $ 0
CONFIG_FILE = pass.dat
SERVER = $ 1
ipaddr = “”
username = “”
password = “”
found = 0
while read line; do
ipaddr = $ (echo $ line | cut-d ‘|’-f1)
username = $ (echo $ line | cut-d ‘|’-f2)
password = $ (echo $ line | cut-d ‘|’-f3)
if ["$ SERVER" == “$ ipaddr”]; then
# The server found!
found = 1
break
fi
done <$ CONFIG_FILE
if [$ found-eq 0]; then
echo “The server not found!”
exit 2
fi
if [-z “$ password”] | | [-z “$ ipaddr”] | | [-z “$ username”]; then
echo “Invalid config file: $ CONFIG_FILE!”
exit 3
fi
echo “Logining (ssh) $ username @ $ ipaddr …”
sshpass-p “$ password” ssh $ username @ $ ipaddr
exit 0
In addition to a record passwords, user names and ssh server IP file pass.dat:
pass.dat:
192.168.0.1 | root | a123B56
192.168.0.2 | root | 7X890Yz
Another problem is that if the first login with ssh when a particular server, ssh will prompt:
The authenticity of host '192 .168.0.1 (192.168.0.11) 'can’t be established.
RSA key fingerprint is 7b: b9: c3: cd: 01: cd: 2f: 19:4 e: 96: d3: 66:27:55:7 f: 65.
Are you sure you want to continue connecting (yes / no)?
The above script does not deal with this situation, interested friends, try to improve what it can own.