ssh免密码登录远程服务器
1、生成密钥。在终端下执行命令:哎,代码跟文字的间距 有问题啊,还没修复。。。。 编辑器里面是没问题,发布出来,就有问题了。
ssh-keygen -t rsa一路回车,各种提示按默认不要改。注意:提示enter passphrase的时候,不要输入,因为你本来就想少打一次密码的,这里如果设置了用密码保护私钥,那登录的时候还是要输密码,就白做了。 2、查看.ssh目录下有个文件,一个公钥(id_rsa.pub),一个私钥(id_rsa)
wubindeMBP:~ nibuw$ ls .ssh/ id_rsa id_rsa.pub known_hosts3、把公钥传送到远程服务器。
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_keys5、修改sshd_config
AuthorizedKeysFile .ssh/authorized_keys UseDNS no PermitRootLogin yes PasswordAuthentication no6、本地登陆远程服务器(指定私钥路径)
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-06-07 20:32
2015-06-01 12:01