免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3171 | 回复: 5
打印 上一主题 下一主题

请问如何实现 ssh 无密码登录 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-03-30 14:49 |只看该作者 |倒序浏览
本帖最后由 longbow0 于 2010-03-30 14:52 编辑

系统环境是这样:

一台超算,有 8 个结点 ( node1~8 ),和 1 个共享的盘阵。在每个结点上,盘阵都被挂载为 /data

用户的主目录在 盘阵 上,为 /data/test

我的做法是,在 node1 上,运行

  1. $ ssh-keygen -t rsa
复制代码
然后在 .ssh 下,

  1. cat id_rsa.pub >> authorized_keys
复制代码
现在的问题是,无论用 rsa1, rsa, dsa 都无法实现无密码登录其他结点。

在各结点去掉 /etc/ssh/sshd_config

  1. # RSAAuthentication yes
  2. # PubkeyAuthentication yes
  3. # AuthorizedKeysFile        %h/.ssh/authorized_keys
复制代码
的注释,重启 sshd 也没有用。

请问还应该考虑哪些因素?谢谢!

论坛徽章:
0
2 [报告]
发表于 2010-03-30 15:58 |只看该作者
rac1-> mkdir ~/.ssh
rac1-> chmod 700 ~/.ssh
rac1-> ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/export/home/oracle/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /export/home/oracle/.ssh/id_rsa.
Your public key has been saved in /export/home/oracle/.ssh/id_rsa.pub.
The key fingerprint is:
87:54:4f:92:ba:ed:7b:51:5d:1d:59:5b:f9:44:da:b6 oracle@rac1.mycorpdomain.com
rac1-> ssh-keygen -t dsa
Generating public/private dsa key pair.
Enter file in which to save the key (/export/home/oracle/.ssh/id_dsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /export/home/oracle/.ssh/id_dsa.
Your public key has been saved in /export/home/oracle/.ssh/id_dsa.pub.
The key fingerprint is:
31:76:96:e6:fc:b7:25:04:fd:70:42:04:1f:fc:9a:26 oracle@rac1.mycorpdomain.com       

在 rac2 上执行

rac2-> mkdir ~/.ssh
rac2-> chmod 700 ~/.ssh
rac2-> ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/export/home/oracle/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /export/home/oracle/.ssh/id_rsa.
Your public key has been saved in /export/home/oracle/.ssh/id_rsa.pub.
The key fingerprint is:
29:5a:35:ac:0a:03:2c:38:22:3c:95:5d:68:aa:56:66 oracle@rac2.mycorpdomain.com
rac2-> ssh-keygen -t dsa
Generating public/private dsa key pair.
Enter file in which to save the key (/export/home/oracle/.ssh/id_dsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /export/home/oracle/.ssh/id_dsa.
Your public key has been saved in /export/home/oracle/.ssh/id_dsa.pub.
The key fingerprint is:
4c:b2:5a:8d:56:0f:dc:7b:bc:e0:cd:3b:8e:b9:5c:7c oracle@rac2.mycorpdomain.com

在 rac1 上执行

rac1-> cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
rac1-> cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys
rac1-> ssh rac2 cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
The authenticity of host 'rac2 (192.168.2.132)' can't be established.
RSA key fingerprint is 63:d3:52:d4:4d:e2:cb:ac:8d:4a:66:9f:f1:ab:28:1f.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'rac2,192.168.2.132' (RSA) to the list of known hosts.
oracle@rac2's password:
rac1-> ssh rac2 cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys
oracle@rac2's password:
rac1-> scp ~/.ssh/authorized_keys rac2:~/.ssh/authorized_keys
oracle@rac2's password:
authorized_keys                           100% 1716     1.7KB/s   00:00

论坛徽章:
0
3 [报告]
发表于 2010-03-30 16:49 |只看该作者
1/ 在每台client上,使用者用 ssh-keygen -t dsa 做出 public key, 把 public key scp 到 ssh 服務器上. public key 在 ~/.ssh/xxx.pub
2/ 在服務器端上, 把各client 的 public key 加到名為 authorized_keys 上.
3/ 更改 ssh 服務器對 auth 的相關設定, 重啟 ssh 服務器, 完成

论坛徽章:
0
4 [报告]
发表于 2010-03-30 16:52 |只看该作者
本帖最后由 longbow0 于 2010-03-30 16:54 编辑

谢谢楼上。

.ssh 目录的属性是 0700,我也尝试过把 authorized_keys 的属性改成 0644 或 0600,还是不行。

结点和盘阵的示意图如下



/data/test 就是用户 test 的 HOME 目录。

ssh-keygen 产生的文件在 /data/test/.ssh/

论坛徽章:
34
亥猪
日期:2015-03-20 13:55:11戌狗
日期:2015-03-20 13:57:01酉鸡
日期:2015-03-20 14:03:56未羊
日期:2015-03-20 14:18:30子鼠
日期:2015-03-20 14:20:14丑牛
日期:2015-03-20 14:20:31辰龙
日期:2015-03-20 14:35:34巳蛇
日期:2015-03-20 14:35:56操作系统版块每日发帖之星
日期:2015-11-06 06:20:00操作系统版块每日发帖之星
日期:2015-11-08 06:20:00操作系统版块每日发帖之星
日期:2015-11-19 06:20:00黄金圣斗士
日期:2015-11-24 10:43:13
5 [报告]
发表于 2010-03-30 17:19 |只看该作者
先把 .pub 的那个放到本机的 authorized_keys 里,登陆自己。

论坛徽章:
0
6 [报告]
发表于 2010-04-08 18:53 |只看该作者
看我的BLOG:witer666.blog.51cto.com
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP