gitlab在ssh登陆时,须要输入密码

看日志,看日志,看日志
重要的事情说三遍html

我本身搭的gitlab,生成了ssh,已经在后台设置好了
之前都是好的,不须要输入密码直接clonegit

IDE集成的git,忽然有一天push不了了shell

单独的git命令,提示要输入密码ubuntu

debug1: Next authentication method: password
git@git.xxxx.com's password:安全

 

==========
解决方法:服务器


方法1:查看客户端的登陆日志app

ssh -vvvT git@git.xxxx.com
查看详细的ssh登陆日志ssh

解决:客户端的问题,能查到
缺点:服务器端的问题不能查到gitlab

方法2:查看服务器的登陆日志测试

服务器:
/usr/sbin/sshd -d -p 8003
打开一个sshd的调试模式


客户端:
ssh -vT git@git.xxxx.com -p 8003

查看服务器上的日志信息
找到对应的错误,解决
参考:https://blog.codefront.net/2007/02/28/debugging-ssh-public-key-authentication-problems


方法3:查看服务器的ssh日志

系统:ubuntu14.04
日志:/var/log/auth.log
查看:tail -f /var/log/auth.log
每一个系统位置名称不同,系统版本会有问题
搜:xxxx(系统 版本号) ssh登陆日志
如:ubuntu14.04 ssh登陆日志

(PS:我这一步,阿里云ECS有问题,系统没有auth.log,怎么打也打不开,我是开工单,作快照,阿里专家才弄好)


方法4:查看gitlab的日志

查看配置
sudo gitlab-rake gitlab:check
查看日志
sudo gitlab-ctl tail
 

==========
解决过程:

通过baidu,google,stackoverflow,各类找,大概的报错和解决方案以下:

方案1:gitlab的ssh没有配置

这个问题在我这不存在,由于之前都是配置好了的,并且一直在用
没有配置的按这个
https://www.cnblogs.com/hafiz/p/8146324.html


方案2:gitlab的系统用户git锁住了

说是git用户锁住了,须要重置密码,而后就能登陆进去了
passwd git
重置密码:123456

而后在
'git@git.xxxx.com's password:
输入123456

能登陆进去了,但进入的是系统的ssh
登陆到了系统的命令行

直接用命令
git clone git@git@git.xxxx.com:testuser/project1.git

提示:

fatal: '/testuser/project1.git' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.


这个没有找到仓库

网上解决方案:

用仓库的绝对目录
git clone git@git@git.xxxx.com:/var/opt/gitlab/git-data/repositories/testuser/project1.git

能够用设置的git的密码clone了

但:
1:不能兼容之前的项目
2:每次要输入密码

问题没有解决


方案3:gitlab的.ssh目录权限和ssh文件权限的问题

/var/opt/gitlab/.ssh/authorized_keys

由于安全问题
不能是755

资料上说:
.ssh:目录权限要是700
authorized_keys:目录权限要是600

但最终我用的是
.ssh:目录权限要是744
authorized_keys:目录权限要是644

也是能够的


方案4:gitlab的端口冲突

修改gitlab的端口
文件:/etc/gitlab/gitlab.rb
修改
gitlab_rails['gitlab_shell_ssh_port'] = 8002

从新编译
sudo gitlab-ctl reconfigure


注意:记得ssh的配置也须要添加端口,才能访问,要否则会报

debug1: connect to address xxx.xxx.xxx.xxx port 8002: Connection refused
ssh: connect to host git.xxxx.com port 8002: Bad file number


文件:/etc/ssh/sshd_config

Port 22
的后面添加
Port 8002

重启ssh
/etc/init.d/ssh restart

测试后,也是同样,是登陆到系统的ssh,不是登陆到gitlab

 

==========

还有几种可能,如:sshd_config中添加AllowUsers git,都试过,都不行

==========

最终解决方案,见前面的,按日志查询,一步一步解决
 

==========

通过一系列的折腾后
根据日志,我出现的问题:

1:ssh没有找到对应的authorized_keys

配置文件
/etc/ssh/sshd_config
取消注释:
AuthorizedKeysFile    %H/.ssh/authorized_keys
修改成:
AuthorizedKeysFile    /var/opt/gitlab/.ssh/authorized_keys


2:报找不到publickey

Failed publickey for git from xxx port xxx ssh2: RSA xx:xx:xx:xx:xx...

1:删除本地除id_rsa和id_rsa.pub
2:删除服务器gitlab的SSHKeys


按日志排除全部的错误后

就能看到正常的

$ ssh  git@git.xxxx.com
Welcome to GitLab, testuser!
Connection to git.xxxx.com closed.

 

==========
gitlab经常使用命令

服务相关
    状态
    sudo gitlab-ctl status
    重启
    sudo gitlab-ctl restart
    开始
    sudo gitlab-ctl start
    中止
    sudo gitlab-ctl stop

官方SSH帮助
https://docs.gitlab.com/ee/ssh/

 

==========
总结:
1:git@git.xxxx.com是系统用户git登陆,输入密码是系统用户git的密码,不是开发者ssh证书的密码
2:gitlab的ssh登陆,是经过系统的ssh功能登陆实现
3:gitlab将全部开发者在后台SSHKey都保存在gitlab的authorized_keys文件中
4:gitlab的ssh关联,可经过配置指定:authorized_keys的位置登陆
5:ssh在登陆时,会找系统的配置文件+关联配置文件登陆
 

========== 但愿能帮助你完全解决gitlab的ssh登陆问题 若是有用,请留言5星好评