linux下配置无密码登陆远程服务器

配置之前你已经安装了ssh,没安装的百度,google……

ssh-keygen  

# 以上命令等价于 ssh-keygen -t rsa 
#-t: 指定密钥的类型 , 默认为 SSH-2 的 rsa 类型 ; 这一步会生成两个秘钥,id_rsa为私钥(客户端用,自己的电脑),id_rsa.pub为公钥(将要连接的远程服务器端用)

ssh-copy-id -i /home/……/.ssh/id_rsa.pub  root@112.205.149.123  #其中/home/……/.ssh/id_rsa.pub为你的电脑生成的公钥的路径,

ssh root@112.205.149.123 #首次连接可能需要输入密码,输入密码,登陆成功,退出,再ssh root@112.205.149.123 ,你会发现不需要密码了,OK。

#上一步可能会出现这个提示

Connection to 101.201.143.162 closed.
 ssh root@101.201.143.162
sign_and_send_pubkey: signing failed: agent refused operation

ssh-add一键解决

/etc/init.d/ssh restart中间可能需要重启。

//实际操作中如果觉得ip不容易记忆,在/etc/hosts 用自己想用的名字绑定ip。


原文地址:https://www.cnblogs.com/wanghaitao/p/9440385.html