10 server ssh security 12.04 sshd
我在 Ubuntu Server 12.04 (A) 上为 SSH 服务器设置公钥身份验证时遇到问题,以便从 Ubuntu Server 13.04 (B) 进行身份验证。
我现在在做什么(我正在尝试按照此处的说明进行操作):
ssh-keygen -C ""
,不使用密码,写入/.ssh/id_rsa
- 我没有收到任何错误ssh-copy-id -i /.ssh/id_rsa user@host-a
- 还有一条成功消息ssh -i /.ssh/id_rsa user@host-a
- 我仍然需要输入我的密码user@host-a
在A上,我检查了/.ssh/authorized_keys
运行后是否修改了ssh-copy-id
,是这种情况。此外,在两台设备上,我都将此添加到/etc/ssh/sshd_config
:
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile /.ssh/authorized_keys
Run Code Online (Sandbox Code Playgroud)
有谁知道这里可能有什么问题?
这是我/var/log/auth.log
在机器 A 上的尾巴:
Jun 13 22:17:56 laptop-camil sshd[12344]: Server listening on 0.0.0.0 port 22.
Jun 13 22:17:56 laptop-camil sshd[12344]: Server listening on :: port 22.
Jun 13 22:18:27 laptop-camil sshd[12345]: Authentication refused: bad ownership or modes for directory /.ssh
Jun 13 22:18:30 laptop-camil sshd[12345]: Accepted password for camilstaps from 164.138.27.37 port 48407 ssh2
Jun 13 22:18:30 laptop-camil sshd[12345]: pam_unix(sshd:session): session opened for user camilstaps by (uid=0)
Jun 13 22:18:35 laptop-camil sshd[12464]: Received disconnect from 164.138.27.37: 11: disconnected by user
Jun 13 22:18:35 laptop-camil sshd[12345]: pam_unix(sshd:session): session closed for user camilstaps
Jun 13 22:18:42 laptop-camil sshd[12516]: Authentication refused: bad ownership or modes for directory /.ssh
Jun 13 22:18:44 laptop-camil sshd[12516]: Connection closed by <host-b> [preauth]
Run Code Online (Sandbox Code Playgroud)
日志文件中的任何内容,尤其是/var/log/auth.log
? 您还可以仔细检查 .ssh 目录和文件的权限。
我自己不必为这种访问修改 sshd_config。我想知道您的修改是否破坏了某些东西,尤其是 AuthorizedKeysFile 行。通常,您希望将 authorized_keys 放在$USER/.ssh
.
以下是我的其中一台服务器上的用户的权限:
:~/.ssh$ ls -ld .
drwx------ 2 rrd rrd 4096 May 28 17:57 .
:~/.ssh$ ll
total 280
-rw-r----- 1 rrd rrd 4351 May 22 16:20 authorized_keys
-rw------- 1 rrd rrd 1679 Apr 27 2012 id_rsa
-rw-r--r-- 1 rrd rrd 399 Apr 27 2012 id_rsa.pub
-rw-r--r-- 1 rrd rrd 266138 Jun 13 00:18 known_hosts
Run Code Online (Sandbox Code Playgroud)
确保单个文件至少受到此限制。
正如 guntbert 指出的,还要检查目录和文件是否归您所有。否则权限将没有意义(或工作)。
谁拥有 B 上的authorized_keys 中的密钥?(在密钥后面说 user@host 的那一点。)它是 root@A 吗?
也就是说,在查看 时~/.ssh/authorized_keys
,bert@etherbert
您的设置相当于什么:
ssh-rsa AAAA...ffsII8dSaDF33 bert@etherbet
Run Code Online (Sandbox Code Playgroud)
我只会手动编辑远程 .ssh/authorized 密钥以进行测试,放入您正在与之建立连接的用户的 id_rsa.pub 内容。
确保您来自在远程 authorized_keys 文件中拥有密钥的用户。
归档时间: |
|
查看次数: |
61198 次 |
最近记录: |