使用公钥
#生成密
ssh-keygen -o -t rsa -f ~/.ssh/my_id_rsa -N '密码' -C '注释'
#查看密钥文件,私钥 my_id_rsa,公钥 my_id_rsa.pub
ls ~/.ssh
#修改配置文件使用生成的密钥
echo -e "Host *\n\tStrictHostKeyChecking no\n\nIdentityFile ~/.ssh/my_id_rsa\n" > ~/.ssh/config
#将公钥传到服务器,然后登陆服务器,将公钥加入信任后就可以免密码登陆
scp ~/.ssh/my_id_rsa.pub <USER>@<HOST>:~/my_id_rsa.pub
ssh <USER>@<HOST>
cat ~/my_id_rsa.pub >> ~/.ssh/authorized_keys
#也可以直接用ssh-copy-id指令直接完成以上操作
ssh-copy-id -i ~/.ssh/my_id_rsa.pub <USER>@<HOST>
使用 sshpass 指令
sshpass -p <PASSWORD> ssh <USER>@<HOST>
sshpass 指令需要安装