ssh免密码登录远程服务器

xue3HohB
xue3HohB 这家伙很懒,还没有设置简介

2 人点赞了该文章 · 2082 浏览

哎,代码跟文字的间距 有问题啊,还没修复。。。。 编辑器里面是没问题,发布出来,就有问题了。

1、生成密钥。在终端下执行命令:
ssh-keygen -t rsa
一路回车,各种提示按默认不要改。注意:提示enter passphrase的时候,不要输入,因为你本来就想少打一次密码的,这里如果设置了用密码保护私钥,那登录的时候还是要输密码,就白做了。 2、查看.ssh目录下有个文件,一个公钥(id_rsa.pub),一个私钥(id_rsa)
wubindeMBP:~ nibuw$ ls .ssh/
id_rsa id_rsa.pub known_hosts
3、把公钥传送到远程服务器。
scp .ssh/id_rsa.pub root@115.28.166.234:/root/.ssh/
4、把id_rsa.pub的内容加入到服务器端的默认验证文件authorized_keys
cat .ssh/id_rsa.pub >> .ssh/authorized_keys
5、修改sshd_config
AuthorizedKeysFile      .ssh/authorized_keys
UseDNS no
PermitRootLogin yes
PasswordAuthentication no
6、本地登陆远程服务器(指定私钥路径)
wubindeMBP:~ nibuw$ ssh -i .ssh/id_rsa root@115.28.166.234
The authenticity of host '115.28.166.234 (115.28.166.234)' can't be established.
RSA key fingerprint is 1a:d0:d4:ef:93:e1:74:1e:f6:c6:67:8b:e1:86:c0:36.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '115.28.166.234' (RSA) to the list of known hosts.
Last login: Tue May 26 01:16:40 2015 from 171.221.147.50
 
Welcome to aliyun Elastic Compute Service!
特别注意:公钥要放在登录服务器所用的账号的家目录下,比如你用 abc登录远程服务器,就要把公钥 放到 /home/root/.ssh/下, authorized_keys文件也是在这个目录下。authorized_keys 的权限应该是600。

发布于 2015-05-31 23:23

免责声明:

本文由 xue3HohB 原创发布于 WeCenter ,著作权归作者所有。

登录一下,更多精彩内容等你发现,贡献精彩回答,参与评论互动

登录! 还没有账号?去注册

xue3HohB
2015-06-07 20:32
其实我是想说,代码块跟文字的间距有问题
zhengqiang
2015-06-01 12:01
@kk 看看