通过jenkins平台找回root服务器登录密码
【背景】
jenkins平台默认执行用户是jenkins,之前辛亏为jenkins用户做了sudo免密操作
突然服务器root密码上不去了
cat /etc/sudoers
## Allow root to run any commands anywhere
root ALL=(ALL) ALL
jenkins ALL=(ALL) NOPASSWD: ALL
【解决思路】
随意找一台可以连接上去的服务器A,通过jenkins用户将A服务器的ssh公钥(/root/.ssh/id_rsa.pub)
通过jenkins用户(jenkins服务器),使用sudo权限写入到/root/.ssh/authorized_keys中(600权限)
【操作流程】
1 默认 /root/.ssh/authorized_keys权限是600,jenkins用户作为other用户,指定是
没有权限写入了,所以jenkins用户可以sudo将其修改为777权限
直接echo数据到 /root/.ssh/authorized_keys会报错
/tmp/jenkins6818882.sh: line 5: /root/.ssh/authorized_keys:
Permission denied
明明给 /root/.ssh/authorized_keys加了权限777为甚还是有权限问题呢
需先看看/root是否 other具体x权限,如果无x权限,other用户就进不去
然后看看/root/.ssh是否 other具体x权限,如果无x权限,other用户就进不去
2 然后就可以使用echo命令(777了不需要sudo)写入公钥到/root/.ssh/authorized_keys
3 记得将权限在恢复