SSH密钥要求输入密码

20

我现在被卡在这里,已经有一个星期了。两天

我有一台安装有Gitlab4和gitolite的CentOS机器。几周以来,一切都运行良好,但是突然在上周末,机器上的所有二进制文件(如yum、python、ruby、mysql等)都消失了,我真的不知道怎么可能会发生这种情况...经过数小时的重新安装和编译,gitlab又可以工作了。

但是,我无法让gitlabgit用户之间的ssh密钥正常工作。我已经删除并重新创建了git用户,重新设置了所有权限,重新创建了ssh密钥,重新安装了gitolite等等。但是什么也没用,我还是得到同样的错误。

git用户的.ssh文件夹

-rwx------ 1 git git  557 Mar 27 16:46 authorized_keys

GitLab用户的.ssh文件夹

-rw------- 1 gitlab gitlab 1671 Mar 27 16:45 id_rsa
-rw-r--r-- 1 gitlab gitlab  406 Mar 27 16:45 id_rsa.pub
-rw-r--r-- 1 gitlab gitlab  391 Mar 27 16:50 known_hosts

SSH错误:

ssh -vvvT git@localhost
OpenSSH_4.3p2, OpenSSL 0.9.8e-fips-rhel5 01 Jul 2008
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug2: ssh_connect: needpriv 0
debug1: Connecting to localhost [127.0.0.1] port 22.
debug1: Connection established.
debug1: identity file /home/gitlab/.ssh/identity type -1
debug3: Not a RSA1 key file /home/gitlab/.ssh/id_rsa.
debug2: key_type_from_name: unknown key type '-----BEGIN'
debug3: key_read: missing keytype
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug2: key_type_from_name: unknown key type '-----END'
debug3: key_read: missing keytype
debug1: identity file /home/gitlab/.ssh/id_rsa type 1
debug1: identity file /home/gitlab/.ssh/id_dsa type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_4.3p2
debug1: match: OpenSSH_4.3p2 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_4.3p2
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug2: kex_parse_kexinit: diffie-hellman-group-exchange-sha1,diffie-hellman-group1-sha1
debug2: kex_parse_kexinit: ssh-rsa,ssh-dss
debug2: kex_parse_kexinit: aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,arcfour,aes192-cbc,aes256-cbc,rijndael-cbc@lysator.liu.se,aes128-ctr,aes192-ctr,aes256-ctr
debug2: kex_parse_kexinit: aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,arcfour,aes192-cbc,aes256-cbc,rijndael-cbc@lysator.liu.se,aes128-ctr,aes192-ctr,aes256-ctr
debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: none,zlib
debug2: kex_parse_kexinit: none,zlib
debug2: kex_parse_kexinit: 
debug2: kex_parse_kexinit: 
debug2: kex_parse_kexinit: first_kex_follows 0 
debug2: kex_parse_kexinit: reserved 0 
debug2: kex_parse_kexinit: diffie-hellman-group-exchange-sha1,diffie-hellman-group1-sha1
debug2: kex_parse_kexinit: ssh-rsa,ssh-dss
debug2: kex_parse_kexinit: aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,arcfour,aes192-cbc,aes256-cbc,rijndael-cbc@lysator.liu.se,aes128-ctr,aes192-ctr,aes256-ctr
debug2: kex_parse_kexinit: aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,arcfour,aes192-cbc,aes256-cbc,rijndael-cbc@lysator.liu.se,aes128-ctr,aes192-ctr,aes256-ctr
debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: none,zlib
debug2: kex_parse_kexinit: none,zlib
debug2: kex_parse_kexinit: 
debug2: kex_parse_kexinit: 
debug2: kex_parse_kexinit: first_kex_follows 0 
debug2: kex_parse_kexinit: reserved 0 
debug2: mac_init: found hmac-md5
debug1: kex: server->client aes128-cbc hmac-md5 none
debug2: mac_init: found hmac-md5
debug1: kex: client->server aes128-cbc hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug2: dh_gen_key: priv key bits set: 132/256
debug2: bits set: 502/1024
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug3: check_host_in_hostfile: filename /home/gitlab/.ssh/known_hosts
debug3: check_host_in_hostfile: match line 1
debug1: Host 'localhost' is known and matches the RSA host key.
debug1: Found key in /home/gitlab/.ssh/known_hosts:1
debug2: bits set: 505/1024
debug1: ssh_rsa_verify: signature correct
debug2: kex_derive_keys
debug2: set_newkeys: mode 1
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug2: set_newkeys: mode 0
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug2: key: /home/gitlab/.ssh/identity ((nil))
debug2: key: /home/gitlab/.ssh/id_rsa (0x848ba50)
debug2: key: /home/gitlab/.ssh/id_dsa ((nil))
debug1: Authentications that can continue: publickey,password
debug3: start over, passed a different list publickey,password
debug3: preferred publickey,keyboard-interactive,password
debug3: authmethod_lookup publickey
debug3: remaining preferred: keyboard-interactive,password
debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Trying private key: /home/gitlab/.ssh/identity
debug3: no such identity: /home/gitlab/.ssh/identity
debug1: Offering public key: /home/gitlab/.ssh/id_rsa
debug3: send_pubkey_test
debug2: we sent a publickey packet, wait for reply
debug1: Authentications that can continue: publickey,password
debug1: Trying private key: /home/gitlab/.ssh/id_dsa
debug3: no such identity: /home/gitlab/.ssh/id_dsa
debug2: we did not send a packet, disable method
debug3: authmethod_lookup password
debug3: remaining preferred: ,password
debug3: authmethod_is_enabled password
debug1: Next authentication method: password

认证日志提供给我的信息是:

Apr  2 10:19:13 venus sshd[15693]: User git not allowed because account is locked
Apr  2 10:19:13 venus sshd[15693]: Failed none for illegal user git from ::ffff:127.0.0.1 port 56906 ssh2
感谢任何帮助。

1
你尝试过使用新的密钥吗? - m79lkm
使用 passwd -u 选项编辑下面的答案。 - VonC
5个回答

27
你提到:
Apr 2 10:19:13 venus shd[15693]: User git not allowed because account is locked 
Apr 2 10:19:13 venus sshd[15693]: Failed none for illegal user git from ::ffff:127.0.0.1 port 56906 ssh2

这篇文章提到:

现在OpenSSH默认检查锁定的账户。
在Linux系统中,锁定的账户是指在/etc/shadow文件的密码字段中包含!!的账户
使用useradd命令创建的账户默认是这种情况
即使您正在使用GSI身份验证并且不需要本地密码,sshd也不会让用户登录,并显示以下消息:

Too many authentication failures for username

sshd的调试信息中,它会指示该账户已被锁定:
User username not allowed because account is locked

以下是关于sshd手册的附加信息: 无论身份验证类型如何,都会检查账户以确保其可访问。 如果账户被锁定、列在DenyUsers中或其组列在DenyGroups中,则该账户不可访问。 锁定帐户的定义取决于系统。 一些平台有自己的帐户数据库(例如AIX),有些修改passwd字段(Solaris和UnixWare上为“*LK*”,HP-UX上为“*”,Tru64上包含“Nologin”,FreeBSD上为前导的“*LOCKED*”,Linux上为前导的“!!”)。 如果需要禁用账户的密码身份验证,同时仍允许公钥身份验证,则应将passwd字段设置为其他值(例如“NP”或“*NP*”)。 解决方法:在/etc/shadow中用(例如)NP替换!!。

正如jszakmeister评论)和Yongcan-Frank-Lv评论)所提到的:

sudo passwd -u git

足以解锁账户


@jszakmeister 是的,我已经将它添加到答案中以增加可见性。 - VonC
1
我之前已经在服务器上安装并运行了一个无头的 Git 服务器。但是当我在同一台服务器上安装 GitLab 后,GitLab 禁用了 "git" 用户。真可惜! - scrat.squirrel

6

这个完全相同的问题曾经困扰了我在gitlab 5.2(bitnami)中的使用。

最终我在/var/log/auth.log中找到了它,显示如下:

May 28 11:32:10 ml115 sshd[27779]: User git not allowed because account is locked
May 28 11:32:10 ml115 sshd[27779]: input_userauth_request: invalid user git [preauth]

在此之后,我很快发现/etc/shadow中的git条目需要用*替换掉一个!。有了*和我的所有密钥设置,我就可以从另一台机器上进行ssh连接了(注意:ssh -vvT git@gitserver也有助于诊断)。
现在git push -u origin master可以正常工作了。
我的系统是Ubuntu 13.04。

有同样的问题:无法往我的 git 仓库推送任何内容,我一直以为是由于非标准 ssh 端口和仅使用密钥进行身份验证引起的,但最终发现问题出在 /etc/shadow 文件中的那个 - Dawid

1
尽管被接受的答案可能起作用,但这可能不是首选方法。
至少在Ubuntu 12.04上,使用“passwd -u git”会导致此警告:
passwd: unlocking the password would result in a passwordless account.
You should set a password with usermod -p to unlock the password of this account.

听起来不错......除了usermod的手册警告不要使用-p选项。

Note: This option is not recommended because the password (or encrypted password)
will be visible by users listing the processes.

相比于以上所有方法,调用passwd -d gitlab可以轻松删除用户密码(它将该密码字段设置为空字符串)。

1
你需要将 ~gitlab/.ssh/id_rsa.pub 添加到 ~git/.ssh/authorized_keys 中。
-rwx------ 1 git git 557 Mar 27 16:46 authorized_keys
-rw-r--r-- 1 gitlab gitlab 406 Mar 27 16:45 id_rsa.pub
我看到大小不匹配,你是否在 authorized_keys 中添加了一些 ssh 密钥选项? 同时,你也应该检查 sshd 的错误日志 (例如:/var/log/auth 或 /var/log/secure 等)。

在auth authorized_keys文件中有一些注释,但即使我只是将id_rsa.pub的内容复制到authorized_keys中,我仍然会收到相同的错误。 - Mario
重新登录并检查位于 /var/log/secure 的 CentOS 的 sshd 日志。由于某些原因,您受到登录限制。(例如:.ssh 上的权限) - Yongcan-Frank-Lu
4月2日10:19:13 Venus sshd[15693]: 用户git不允许登录,因为账户已被锁定。 4月2日10:19:13 Venus sshd[15693]: 来自::ffff:127.0.0.1端口56906的非法用户git登录失败。 - Mario
2
passwd -u <用户名> 将解锁用户,并使用更新 /etc/shadow 的相同技巧。 - Yongcan-Frank-Lu

0
最简单的解锁用户的方法:usermod -p '*' username


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接