Tag Archives: SSH

使用公钥认证免密码SSH登录的一般步骤和问题排除

一般步骤: 1、ssh-keygen,一路回车,不设密码,程序便会在~/home/.ssh下生成id_rsa私钥和id_rsa.pub公钥 2、ssh-copy-id username@remotehost,程序会将步骤一生成的公钥添加到remotehost:/home/username/.ssh/authorized_keys中。如果没有remotehost:/home/username/.ssh/目录,应该手动创建 问题排除: 检查remotehost的/etc/ssh/sshd_config: AllowUsers或AllowGroups如果被定义,username应该在指定的用户列表或用户组里 DenyUsers或DenyGroups如果被定义,username应该不在…… AuthorizedKeysFile应该设为.ssh/authorized_keys RSAAuthentication和PubkeyAuthentication应该设为yes 如果使用root登录,PermitRootLogin应该设为noyes 修改/etc/ssh/sshd_config之后别忘了重启sshd 检查本地的id_rsa.pub的内容确实被添加到remotehost:/home/username/.ssh/authorized_keys 检查remotehost的/etc/hosts 将本地机器的ip和主机名添加进去 修改remotehost:/home/username/.ssh/权限,该目录应该其它用户可读可执行 chmod o+rx -R .ssh 删除用户组读写执行权限 chmod g-rwx -R .ssh 调试: 盯着remotehost的日志文件。不同的发行系列,sshd的日志路径可能不同 remotehost: sudo tail -f /var/log/secure 开启本地ssh的调试日志输出 ssh -v username@remotehost 如果sshd日志输出:“Authentication refused: bad ownership … Continue reading

Posted in Uncategorized | Tagged | Leave a comment