ssh连接gitlab失败

报错如下:

ssh: connect to host xxx.xxx.xxx.xxx port xxxx: Connection refused

排查了好久发现原因竟然是gitlab所在环境的密钥文件权限过大!

解决方法:

  1. 进入docker容器。不是docker部署的忽略这一步。
docker exec -it gitlab bash
  1. 重启ssh服务。这一步是为了找出哪些文件权限有问题,如果没有问题,就会重启成功,说明不是文件权限的原因导致的。
service ssh restart

结果如下:

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0777 for '/etc/ssh/ssh_host_rsa_key' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
key_load_private: bad permissions
Could not load host key: /etc/ssh/ssh_host_rsa_key
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0777 for '/etc/ssh/ssh_host_dsa_key' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
key_load_private: bad permissions
Could not load host key: /etc/ssh/ssh_host_dsa_key
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0777 for '/etc/ssh/ssh_host_ecdsa_key' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
key_load_private: bad permissions
Could not load host key: /etc/ssh/ssh_host_ecdsa_key
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0777 for '/etc/ssh/ssh_host_ed25519_key' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
key_load_private: bad permissions
Could not load host key: /etc/ssh/ssh_host_ed25519_key
/var/run/sshd must be owned by root and not group or world-writable.
  1. 修改列出的这些文件的权限。
chmod 700 /etc/ssh/ssh_host_rsa_key
chmod 700 /etc/ssh/ssh_host_dsa_key
chmod 700 /etc/ssh/ssh_host_ecdsa_key
chmod 700 /etc/ssh/ssh_host_ed25519_key

再次重启ssh发现还有报错:

/var/run/sshd must be owned by root and not group or world-writable.

直接删除这个文件夹:

rm -rf /var/run/sshd/

再次service ssh restart

* Restarting OpenBSD Secure Shell server sshd                                                                                                                                                         [ OK ]

成功!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
问题: gitlab启动失败 回答: 如果Gitlab启动失败,可以尝试以下解决方法。首先,通过终止服务命令停止阻塞服务,使用命令systemctl stop xxx.service来停止服务。然后,再次启动gitlab-runsvdir.service,使用命令systemctl start gitlab-runsvdir.service来正常启动。如果仍然无法启动,可以尝试使用命令gitlab-ctl start来手动启动Gitlab服务。[1] 如果以上方法无效,可以尝试以下步骤。首先,打开Git服务器(192.168.4.20),使用命令podman ps -a查看容器ID,然后使用命令podman stop关闭容器,再使用命令podman rm删除容器。接下来,编辑/etc/ssh/sshd_config文件,将端口改回22,并使用命令systemctl restart ssh重启服务。退出当前SSH连接,重新远程连接到服务器(192.168.4.20)。然后,使用命令rm -rf /var/lib/git/myproject删除目录,再使用命令mkdir -p /var/lib/git创建目录。接下来,在/var/lib/git目录下使用命令git init /var/lib/git/myproject创建仓库。[2] 如果问题仍然存在,可以尝试以下步骤。首先,打开开发服务器(192.168.4.10),使用命令rm -rf /root/myproject删除仓库。然后,使用命令git clone 192.168.4.20:/var/lib/git/myproject将服务器上的仓库拷贝到本地。进入仓库目录,使用命令cd myproject。接下来,将二阶段lnmp_soft.tar.gz中的www_template.zip解压并拷贝到myproject目录中。使用命令git add .将修改保存到暂存区,使用命令git commit -m "update"将修改保存到本地,使用命令git push将修改保存到远程服务器。如果需要添加标签,可以使用命令git tag v1添加标签,然后使用命令git push -u origin v1将标签保存到origin服务器。[3]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值