使用SSH公钥(id_dsa.pub)实现免密码登录
首先,在本地机器上产生公钥:
Java代码
[root@localhost .ssh]# ssh-keygen -d 一直按回车键
Generating public/private dsa key pair.
Enter file in which to save the key (/root/.ssh/id_dsa):
/root/.ssh/id_dsa already exists.
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_dsa.
Your public key has been saved in /root/.ssh/id_dsa.pub.
The key fingerprint is:
89:77:aa:a2:d8:31:35:1e:3a:34:9e:b9:da:ea:62:34 root@localhost.localdomain
[root@localhost .ssh]#
然后把产生的公钥传到想要登陆的远程机器上,如果是root用户登陆远程的话,把公钥放在/root/.sshd目录下面。
Java代码
[root@localhost .ssh]# scp /root/.ssh/id_dsa.pub root@192.168.0.60:/root/.ssh/
root@192.168.0.60's password: 需输入远程机器的登录密码
id_dsa.pub 100% 616 0.6KB/s 00:00
并修改该文件的名称:
Java代码
[root@web1 .ssh]# mv id_dsa.pub authorized_keys
最终实现ssh的免密码登陆。
SSH免密码登陆效果:
Java代码
[root@localhost .ssh]# ssh root@192.168.0.60
Last login: Tue Sep 27 09:03:10 2011 from 192.168.0.3
[root@web1 ~]#
作者“天堂鸟”
相关新闻>>
- 发表评论
-
- 最新评论 更多>>