ssh 登录不用输密码

ssh 登陆不用输密码

检查远端主机配置

先 ssh 到远端主机

sudo vim /etc/ssh/sshd_config

保证以下这几项开启

RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile  .ssh/authorized_keys

重启 sshd

sudo service sshd restart

生成本地公钥

ssh-keygen

可以默认一路确定

copy 公钥到远程主机

ssh-copy-id [email protected]

然后输入密码.

下次用:

就可以直接登录了.

问题

如果还是会要求输入密码,可以用

来看登录信息

debug1: Unspecified GSS failure.  Minor code may provide more information
Credentials cache file '/tmp/krb5cc_1000' not found

debug1: Unspecified GSS failure.  Minor code may provide more information
Credentials cache file '/tmp/krb5cc_1000' not found

debug1: Unspecified GSS failure.  Minor code may provide more information


debug1: Unspecified GSS failure.  Minor code may provide more information


debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/bigzhu/.ssh/id_rsa
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Trying private key: /home/bigzhu/.ssh/id_dsa
debug1: Next authentication method: password

到远程主机查看日志

sudo tail -f /var/log/secure
Feb  1 17:34:27 (none) sshd![pic](9246): Authentication refused: bad ownership or modes for directory /home/bigzhu/.ssh
Feb  1 17:34:27 (none) sshd![pic](9246): Authentication refused: bad ownership or modes for directory /home/bigzhu/.ssh

这个目录的权限不对,我汗

chmod 700 .ssh

搞定

ubuntu 下查看日志

ubuntu 真麻烦

先改 ssh 的日志级别

sudo vim /etc/ssh/sshd_config
LogLevel INFO
改为
LogLevel VERBOSE

报错2

Aug 14 14:48:11 localhost sshd![pic](17697): Authentication refused: bad ownership or modes for directory /home/oracle

这是整个用户的目录权限都不对. 要求是 700 或者 755 才行

chmod 755 /home/oracle

通常使用

chmod 700 .ssh
chmod 755 ./