我尝试在我的 Mac 和 CentOS dedi 服务器之间设置 PubKey 身份验证,但出现了问题……
以下是我采取的步骤:
ssh-keygen -t rsa
然后
chmod 700 .ssh/ && chmod 600 .ssh/*
然后
scp id_rsa.pub root@dedi:~/.ssh/authorized_keys
然后(抱歉,我加了这么多“然后”)
ssh root@dedi
你知道吗?系统提示我输入密码。
有什么想法吗?谢谢!
编辑:这是输出ssh -v root@dedi
:
SH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011
debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for dedi
debug1: Connecting to dediserversdomain.com.au.co.net.org.bz [198.100.145.168] port 22.
debug1: Connection established.
debug1: identity file /Users/someone/.ssh/id_rsa,~/.ssh/id_dsa type -1
debug1: identity file /Users/someone/.ssh/id_rsa,~/.ssh/id_dsa-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.2
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.3
debug1: match: OpenSSH_5.3 pat OpenSSH_5*
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Server host key: RSA (my rsa key)
debug1: Host 'dediserversdomain.com.au.co.net.org.bz' is known and matches the RSA host key.
debug1: Found key in /Users/someone/.ssh/known_hosts:1
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Next authentication method: publickey
debug1: Trying private key: /Users/someone/.ssh/id_rsa,~/.ssh/id_dsa
debug1: Next authentication method: password
[email protected]'s password:
编辑:我的 dedi 的输出stat .ssh
和stat .ssh/*
内部输出:
File: `.ssh'
Size: 4096 Blocks: 8 IO Block: 4096 directory
Device: 801h/2049d Inode: 1175048 Links: 2
Access: (0700/drwx------) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2014-09-21 11:21:43.000000000 -0400
Modify: 2014-09-21 10:52:26.000000000 -0400
Change: 2014-09-21 11:21:49.000000000 -0400
File: `.ssh/authorized_keys'
Size: 411 Blocks: 8 IO Block: 4096 regular file
Device: 801h/2049d Inode: 1175045 Links: 1
Access: (0600/-rw-------) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2014-09-21 10:52:26.000000000 -0400
Modify: 2014-09-21 10:52:26.000000000 -0400
Change: 2014-09-21 11:21:43.000000000 -0400
编辑:这是输出/usr/sbin/sshd -d
debug1: sshd version OpenSSH_5.3p1
debug1: read PEM private key done: type RSA
debug1: private host key: #0 type 1 RSA
debug1: read PEM private key done: type DSA
debug1: private host key: #1 type 2 DSA
debug1: rexec_argv[0]='/usr/sbin/sshd'
debug1: rexec_argv[1]='-d'
Set /proc/self/oom_score_adj from 0 to -1000
debug1: Bind to port 22 on 0.0.0.0.
Bind to port 22 on 0.0.0.0 failed: Address already in use.
debug1: Bind to port 22 on ::.
Bind to port 22 on :: failed: Address already in use.
Cannot bind any address.
编辑:这是输出grep 'sshd' /var/log/*
:二进制文件 /var/log/btmp 匹配二进制文件 /var/log/btmp-20140901 匹配 /var/log/dovecot-info.log:Aug 08 09:10:03 pop3-login:信息:已断开连接(身份验证失败,1 次尝试):用户=,方法=PLAIN,rip=211.43.207.112,lip=198.100.145.168 /var/log/install_rtm.log:rtm hINFO_TCP_LISTEN_IP-0-0-0-0_PORT-22_procname|sshd /var/log/install_rtm.log:rtm hINFO_TCP_LISTEN_IP-0-0-0-0_PORT-22_cmdline|/usr/sbin/sshd /var/log/install_rtm.log:rtm hINFO_TCP_LISTEN_IP-0-0-0-0_PORT-22_exe|/usr/sbin/sshd /var/log/install_rtm.log:rtm hINFO_TCP_LISTEN_IP-0_PORT-22_procname|sshd /var/log/install_rtm.log:rtm hINFO_TCP_LISTEN_IP-0_PORT-22_cmdline|/usr/sbin/sshd /var/log/install_rtm.log:rtm hINFO_TCP_LISTEN_IP-0_PORT-22_exe|/usr/sbin/sshd
答案1
在 /etc/ssh/sshd_config 中,设置LogLevel
为DEBUG3
,然后service sshd restart
tail -F /var/log/secure > /root/tmp.txt
:这是一种获取与测试相关的日志的有效方法;尽管你会事先得到几行旧日志。它似乎会挂起(如果你愿意,你可以把它放在后台)
尝试再次进行身份验证(可能失败)。终止tail -F ...
您之前启动的作业。失败的原因很可能会在中看到/root/tmp.txt
。
大多数情况下,这是由于您的输入格式不正确(或换行)/root/.ssh/authorized_keys
(请注意美式英语拼写)。
其他常见原因:
AllowRoot
设置为否;PubKeyAuthentication
设置为 no(请注意RSAAuthentication
,这适用于 SSH 版本 1(应禁用))
您或许还在寻找一个对Limit
您有不同感受的诗节。
答案2
检查 selinux 是否正在运行
sestatus
暂时关闭
setenforce 0
如果您随后被允许登录,您有两个选择:您可以通过编辑永久关闭它:
/etc/sysconfg/selinux
我不记得这个文件到底是什么样子的,但如果我记得的话,它非常简单。
或者,您可以确保在 .ssh 文件夹和文件上正确设置了 selinux 上下文
restorecon -R ~/.ssh
答案3
selinux 是否已打开?检查 /var/log/messages 以检查。如果 selinux 不是问题所在。尝试停止 sshd 服务并在控制台上启动它:
user@server# /usr/sbin/sshd -d
这没有帮助,因为您已经在使用主守护进程的端口。
Bind to port 22 on :: failed: Address already in use.
Cannot bind any address.
SSHD 公钥认证可能因以下情况失败:
- 服务器用户主目录 ~/.ssh 上的权限无效,权限不是 700(尝试检查权限是否与您在 src 上设置的权限相同)
- ~/.ssh/authorized_keys 的权限不是 600(尝试检查权限是否与你在 src 上设置的权限相同)
- ~/.ssh 或 ~/.ssh/authorized_keys 的所有者不同(如果您与您的用户一起使用 scp,我认为这可能不是问题)
- SElinux 配置错误
- 错误的按键设置
您可以查看
#tail -f /var/log/secure
当您尝试连接时