您的位置:首页 > 其它

ssh免密码登录实验

2011-05-30 11:14 92 查看
客户机:10.1.29.15

目标机:10.1.29.75 用户名:root 密码:f

从客户机登录到目标机

在客户机上生成密钥,一直敲回车即可,把公钥/root/.ssh/id_rsa.pub拷贝到目标主机。

root@alen:~# 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:
ca:8b:af:b2:2d:07:0c:27:8d:d6:ac:02:2b:94:f0:85 root@alen
The key's randomart image is:
+--[ RSA 2048]----+
|   .             |
|. E .            |
|.++.             |
|=++o             |
|+*.     S        |
|+.o  . .         |
|o  .  o          |
|  o... .         |
|  .=+oo          |
+-----------------+
root@alen:~# scp ~/.ssh/id_rsa.pub 10.1.29.75:~/.ssh/


先登录目标主机。

root@alen:~# ssh 10.1.29.75
root@10.1.29.75's password:
Last login: Mon May 30 10:43:55 2011 from 10.1.29.15
[root@n75 ~]# cd ~/.ssh


放入授权文件.ssh/authorized_keys中,保证对~/.ssh和~/.ssh/id_rsa* ~/.ssh/authorized_keys都有写权限。

[root@n75 .ssh]# cat id_rsa.pub >> ~/.ssh/authorized_keys
[root@n75 .ssh]# chmod 700 ~/.ssh
[root@n75 .ssh]# chmod 600 ~/.ssh/id_rsa* ~/.ssh/authorized_keys


然后退出再登录,就不用密码了。

[root@n75 .ssh]# exit
logout
Connection to 10.1.29.75 closed.
root@alen:~# ssh 10.1.29.75
Last login: Mon May 30 10:58:05 2011 from 10.1.29.15
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: