ssh免密码登录

一、生成公钥和私钥

 打开终端(命令行),执行命令(ssh -keygen),一直回车,即可得到公钥和私钥。

公钥和私钥就自动生成在 ~/.ssh目录下,如图:

其中 id_rsa为私钥,id_rsa.pub为公钥,都是文本文件 可以直接vim进行编辑

二、导入公钥到认证文件,更改权限

执行命令(cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys)

执行命令(chmod 600 .ssh/authorized_keys)

三、编辑config文件(不存在创建一个config文件)

Host remotehostname
Hostname remotehostname
Port 10000
User userThatLoginRemoteHost
IdentityFile ~/.ssh/id_rsa

写入config文件

四、将本机authorized_keys内容复制到服务器上的authorized_keys文件中即可

echo 'xxxxxxx' >>.ssh/authorized_keys

五、ssh别名,编辑本地config文件插入已下内容

Host 'name'

HostName '121.xx.xx.xx'
User root
IdentitiesOnly yes

 

posted @ 2018-04-08 18:28  听风忆雨丶  阅读(85)  评论(0编辑  收藏  举报