linux ssh无密码登录
然后把公钥放到服务器上(~/.ssh/authorized_keys), 自己保留好私钥.在使用ssh登录时,ssh程序会发送私钥去和服务器上的公钥做匹配.如果匹配成功就可以登录了。步骤如下:
1.在本地机器上生成密码对
[root@sg201 .ssh]# 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:
64:4e:53:ff:4b:f9:e4:34:6c:e0:45:5c:1f:20:c6:81 root@sg201
这时可以 看到在/root/.ssh下生成了私钥id_rsa和公钥id_rsa.pub这两个文件
[root@sg201 .ssh]# ls
id_rsa id_rsa.pub known_hosts
2.将公钥拷到服务器端/root/.ssh下并安装
[root@sg201 .ssh]# scp id_rsa.pub root@sg203:/root/.ssh
root@sg203's password:
id_rsa.pub 100% 392 0.4KB/s 00:00
登录服务器sg203进行如下操作
[root@sg203 .ssh]#cat id_rsa.pub >> authorized_keys
[root@sg203 .ssh]# ls
authorized_keys id_rsa.pub known_hosts
[root@sg203 .ssh]# ls -l
total 12
-rw-r--r-- 1 root root 392 Jul 12 14:18 authorized_keys
-rw-r--r-- 1 root root 392 Jul 12 14:17 id_rsa.pub
-rw-r--r-- 1 root root 1183 Jul 10 16:29 known_hosts
[root@sg203 .ssh]# chmod 600 authorized_keys //权限的设置非常重要,因为不安全的设置安全设置,会让你不能使用RSA功能
3.在服务器sg203上开启ssh服务的Pubkey认证功能,操作方法如下
[root@sg203 ssh]#vi /etc/ssh/sshd_config
RSAAuthentication yes
PubkeyAuthentication yes
然后重启ssh服务 service sshd restart
这时在sg201上就可以实现对sg203的无密码登录了
[root@sg201 ~]# ssh sg203
Last login: Thu Jul 12 14:45:25 2012 from sg201
[root@sg203 ~]#
待解决问题:这里用root帐号实现了ssh无密码登录,但我用新建的普通帐号hadoop却不行,不知是什么原因?
更多推荐
所有评论(0)