ssh登录报错

468 阅读1分钟

ssh登录报错

ssh登录报错 Permission denied (publickey)

scp远程拷贝文件时提示错误: Warning: Permanently added '10.0.0.182' (RSA) to the list of known hosts. Permission denied (publickey). 解决: 登录10.0.0.182,将/etc/ssh/sshd_config文件中的PasswordAuthentication no 改为PasswordAuthentication yes

重启sshd服务:/etc/init.d/sshd restart 问题解决。

原因:scp是基于ssh的拷贝服务,ssh在没有密钥登录的情况下,禁用了密码登录,故出现如上错误。

设置免密登录

本机:cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys

copy id_rsa.pub到需要免密机器(虚拟机) 执行:cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys

执行

chmod 755 ~

chmod 700 ~/.ssh

chmod 600 ~/.ssh/authorized_keys

参考:blog.csdn.net/zengqiang1/…

注意:相互免密

不修改权限会报错

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ WARNING: UNPROTECTED PRIVATE KEY FILE! @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ Permissions 0664 for '/home/ubuntu2/.ssh/id_rsa' are too open. It is required that your private key files are NOT accessible by others. This private key will be ignored. bad permissions: ignore key: /home/ubuntu2/.ssh/id_rsa Permission denied (publickey).

cd ~/.ssh && ll -hl -rw------- 1 user user 408 10月 24 14:03 authorized_keys

-rw------- 1 user user 1679 6月 28 14:50 id_rsa

-rw-r--r-- 1 user user 408 6月 28 14:50 id_rsa.pub

-rw-r--r-- 1 user user 5324 10月 24 13:16 known_hosts

chmod 600 ~/.ssh/id_rsa

chmod 644 ~/.ssh/id_rsa.pub