SSH 免密登录vscode 附debug
关键词 :vscode ssh ssh无法免密登录 ssh免密登录失败
1 sshd 的配置文件/etc/ssh/sshd_config,
确保公钥登录开启
PubkeyAuthentication yes
2 生成公钥并上传
ssh-keygen
找到本地 .ssh/id_rsa.pub
将其中文本内容搞到服务器的 ~/.ssh/authorized_keys
2.1 命令行
ssh-copy-id 用户名@ip地址
如
ssh-copy-id mi@192.168.0.1
2.2手动
确保是用户新建~/.ssh/authorized_keys
mkdir ~/.ssh
touch ~/.ssh/authorized_keys
复制也好上传文件也行,不管什么方法只要将 本地的id_rsa.pub里的东西搞到服务器的authorized_keys就行
3 附 debug 免密登录失败问题排查
主要根据输出信息找问题
调整日志级别服务端/etc/ssh/sshd_config
LogLevel DEBUG
服务端获取日志
sudo tail -f -n 500 /var/log/auth.log | grep sshd
客户端 SSH debug 模式,获取客户端详细登录日志
ssh -vvv 192.168.0.1
当出现 authorized_keys’: Permission denied 之时说明有两种情况
sshd[28422]: debug1: Could not open authorized keys '/home/mi/.ssh/authorized_keys': Permission denied
sshd[28422]: debug1: restore_uid: 0/0
sshd[28422]: debug1: temporarily_use_uid: 1000/1000 (e=0/0)
sshd[28422]: debug1: trying public key file /home/mi/.ssh/authorized_keys2
sshd[28422]: debug1: Could not open authorized keys '/home/mi/.ssh/authorized_keys2': Permission denied
3.1 权限不对
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
3.2 你是用root新建.ssh及authorized_keys
请删除.ssh及authorized_keys
确保是用户新建