auto login for ssh

本笔记记录freebsd系统下通过ssh自动登陆到另一台服务器的过程。本笔记虽然是在FreeBSD8.2系统上测试通过,但其中多数内容也适合各个Linux发行版本以及各个BSD分支,在其它系统上只需要做少量调整。
实现效果:在freebsd服务器B上可以不用输入密码自动登陆freebsd服务器A
配置步骤:
一、在freebsd服务器A上执行以下命令生成public/private rsa密匙对:
[[email protected] ~]# ssh-keygen -t rsa

Generating public/private rsa key pair.
定义密匙文件保存位置
Enter file in which to save the key (/root/.ssh/id_rsa):
这一步不要输入密码,直接回车
Enter passphrase (empty for no passphrase): 
这一步不要输入密码,直接回车
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
fa:8d:7b:d4:82:62:3f:7f:b8:d1:03:37:6c:d9:2d:b8 [email protected]
The key's randomart image is:
+--[ RSA 2048]----+
|                 |
|                 |
|                 |
|           . + . |
|        S...B o .|
|      o.. o=.o . |
|     ..o ..oE    |
|       .ooo...   |
|        +=+o     |
+-----------------+

二、到密匙文件保存位置设置权限:
[[email protected] ~]# cd /root/.ssh/
[root@www.service-labs.com ~]# cat id_rsa.pub >> authorized_keys
[[email protected] ~]# chmod 600 authorized_keys

三、通过scp方式拷贝id_rsa文件到freebsd服务器B上:
[[email protected] ~]# scp id_rsa [email protected]_server_B_IP:/root/.ssh/

四、在freebsd服务器B上执行命令:
[[email protected] ~]# chmod 600 /root/.ssh/id_rsa

五、现在在freebsd服务器B上登陆freebsd服务器A就不用密码了!
[[email protected] ~]# ssh root@www.service-labs.com

原文链接:,转发请注明来源!

发表评论