一般的ssh登陆都要求输入密码,一般采用的方式是建立SSH等效性,即ssh-keygen;ssh-copy-id
当某些情况下以上方式不适用的时候可以考虑如下方式:
采用命令sshpass传递密码
无sshpass命令的话可以先安装sshpass:yum install sshpass
英文HELP:
Usage: sshpass [-f|-d|-p|-e] [-hV] command parameters
-f filename Take password to use from file
-d number Use number as file descriptor for getting password
-p password Provide password as argument (security unwise)
-e Password is passed as env-var "SSHPASS"
With no parameters - password will be taken from stdin
-h Show help (this screen)
-V Print version information
At most one of -f, -d, -p or -e should be used
使用:
sshpass -p 123456 ssh -o StrictHostKeyChecking=no root@x.x.x.x -- command
StrictHostKeyChecking=no #不进行公钥认证,即第一次ssh登陆的时候选yes/no?
以上方法对于周期执行简单的命令还是可的