前段时间在给公司的gitlab迁移服务器,过程也很简单,备份数据库,打包程序文件,打包启动项文件到新的服务器。
在新的服务器启动gitlab,可以正常启动,但是却遇到了一个奇葩的问题:
git pushgit pull 的时候,却提示验证失败。无法识别SSH KEY,尝试过删除了,然后重新添加SSH KEY也不行。
最后经过多层次的Google,才找到以下资料:

public-key-authentication-fails-only-when-sshd-is-daemon
一次由SELinux引起的ssh公钥认证失败问题

得到的原因是:是因为.ssh目录没有ssh_home_t标签!!

既然知道了原因,那么接近也比较简单了。
通过下面命令重置:

[root@249 ~]# restorecon -r -vv /root/.ssh
[root@249 ~]# restorecon -r -vv .ssh
restorecon reset /root/.ssh context unconfined_u:object_r:admin_home_t:s0->unconfined_u:object_r:ssh_home_t:s0
restorecon reset /root/.ssh/id_rsa context unconfined_u:object_r:admin_home_t:s0->unconfined_u:object_r:ssh_home_t:s0
restorecon reset /root/.ssh/known_hosts context unconfined_u:object_r:admin_home_t:s0->unconfined_u:object_r:ssh_home_t:s0
restorecon reset /root/.ssh/authorized_keys context unconfined_u:object_r:admin_home_t:s0->unconfined_u:object_r:ssh_home_t:s0
restorecon reset /root/.ssh/id_rsa.pub context unconfined_u:object_r:admin_home_t:s0->unconfined_u:object_r:ssh_home_t:s0