`
vfate_linux
  • 浏览: 240849 次
  • 性别: Icon_minigender_1
  • 来自: 上海
文章分类
社区版块
存档分类
最新评论

ssh keygen后登陆无效解决

阅读更多
设置无密码登陆,结果出错无效.
ssh-keygen,

错误的设置方式:
登陆到远程主机:mkdir .ssh && chmod 700 .ssh
本地:scp .ssh/id_rsa.pub root@your_remote_host
结果登陆还是提示要求输入密码.... ++ 试了好多次,权限啥的都是完全正确的...就是不行...


后来发现,正确的设置方式:
登陆到远程主机:mkdir .ssh && chmod 700 .ssh
本地:ssh-copy-id -i .ssh/id_rsa.pub root@your_remote_host
ok成功了~~

错误的设置时,ssh显示调试信息:ssh -vvv -oPreferredAuthentications=publickey root@your_remote_host
错误的调试信息如下,供参考:
引用
OpenSSH_5.2p1, OpenSSL 1.0.1c 10 May 2012
debug1: Reading configuration data /usr/local/etc/ssh_config
debug2: ssh_connect: needpriv 0
debug1: Connecting to 192.168.0.113 [192.168.0.113] port 22.
debug1: Connection established.
debug1: identity file ~/.ssh/identity type -1
debug3: Not a RSA1 key file /home/gototouch/.ssh/id_rsa.
debug2: key_type_from_name: unknown key type '-----BEGIN'
debug3: key_read: missing keytype
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug2: key_type_from_name: unknown key type '-----END'
debug3: key_read: missing keytype
debug1: identity file ~/.ssh/id_rsa type 1
debug1: identity file ~/.ssh/id_dsa type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.3
debug1: match: OpenSSH_5.3 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.2
debug2: fd 3 setting O_NONBLOCK
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug2: kex_parse_kexinit: diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
debug2: kex_parse_kexinit: ssh-rsa,ssh-dss
debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.se
debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.se
debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: none,zlib@openssh.com,zlib
debug2: kex_parse_kexinit: none,zlib@openssh.com,zlib
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit: first_kex_follows 0
debug2: kex_parse_kexinit: reserved 0
debug2: kex_parse_kexinit: diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
debug2: kex_parse_kexinit: ssh-rsa,ssh-dss
debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.se
debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.se
debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: none,zlib@openssh.com
debug2: kex_parse_kexinit: none,zlib@openssh.com
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit: first_kex_follows 0
debug2: kex_parse_kexinit: reserved 0
debug2: mac_setup: found hmac-md5
debug1: kex: server->client aes128-ctr hmac-md5 none
debug2: mac_setup: found hmac-md5
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug2: dh_gen_key: priv key bits set: 121/256
debug2: bits set: 499/1024
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug3: check_host_in_hostfile: filename /home/gototouch/.ssh/known_hosts
debug3: check_host_in_hostfile: match line 6
debug1: Host '192.168.0.113' is known and matches the RSA host key.
debug1: Found key in ~/.ssh/known_hosts:6
debug2: bits set: 522/1024
debug1: ssh_rsa_verify: signature correct
debug2: kex_derive_keys
debug2: set_newkeys: mode 1
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug2: set_newkeys: mode 0
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug2: key: ~/.ssh/id_rsa (0x15fce10)
debug2: key: ubuntuhost@gmail.com (0x1604210)
debug2: key: ~/.ssh/identity ((nil))
debug2: key: ~/.ssh/id_dsa ((nil))
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug3: start over, passed a different list publickey,gssapi-keyex,gssapi-with-mic,password
debug3: preferred publickey
debug3: authmethod_lookup publickey
debug3: remaining preferred:
debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Offering public key: ~/.ssh/id_rsa
debug3: send_pubkey_test
debug2: we sent a publickey packet, wait for reply
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Offering public key: ubuntuhost@gmail.com
debug3: send_pubkey_test
debug2: we sent a publickey packet, wait for reply
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Trying private key: ~/.ssh/identity
debug3: no such identity: ~/.ssh/identity
debug1: Trying private key: ~/.ssh/id_dsa
debug3: no such identity: ~/.ssh/id_dsa
debug2: we did not send a packet, disable method
debug1: No more authentication methods to try.
Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).


后记:本人仔细看了下/usr/bin/ssh-copy-id的脚步,发现了centos的restorecon命令起的作用,测试了下如下方式也是可以有效的不用密码登陆:
远程执行:mkdir .ssh && chmod 700 .ssh
本地执行:cat ~/.ssh/id_rsa.pub | ssh root@your_host 'cat -  >> .ssh/authorized_keys'
远程执行:restorecon .ssh .ssh/authorized_keys
最后一步是成功的保证

参考:1.http://askubuntu.com/questions/54670/passwordless-ssh-not-working
2.http://www.linuxquestions.org/questions/linux-software-2/ssh-keygen-for-auto-ssh-login-not-working-929325/
分享到:
评论

相关推荐

    SSH登陆实例文件和工程

    4. **安全注意事项**:尽管SSH提高了安全性,但仍需注意安全实践,例如定期更换私钥,限制无效登陆尝试,使用防火墙限制SSH访问端口,以及启用SSH的最新版本以获取最新的安全补丁。 在提供的压缩包中,可能包含的...

    ssh注册登录项目

    3. **密钥生成**:使用`ssh-keygen`命令生成公钥和私钥对。用户可以选择RSA、ECDSA或Ed25519等不同的算法。 4. **公钥认证**:将本地公钥复制到远程服务器的`~/.ssh/authorized_keys`文件中,实现无密码登录。`ssh-...

    ssh实战项目.zip

    13. **安全最佳实践**:定期更换SSH密钥,限制无效尝试的次数,使用强壮的密码或密钥,禁用弱加密套件,以及监控SSH日志,是保持SSH安全的重要措施。 以上是SSH实战项目中涉及的关键技术点。在实际项目中,可能还...

    ssh整合适合新手

    4. **生成密钥对**:使用`ssh-keygen`命令生成公钥和私钥。公钥可上传到服务器,私钥保留在本地,实现无密码登录。 5. **SSH连接**:使用`ssh user@hostname`命令进行连接,初次连接可能需要确认主机指纹。如果配置...

    ssh 连接Linux系统工具

    10. **安全最佳实践**:定期更换SSH密钥,限制无效尝试的次数,使用非标准端口,禁用弱加密套件,监控`sshd`日志,这些都是提高SSH安全性的关键措施。 通过理解以上知识点,你可以更好地使用和管理SSH连接,确保在...

    ssh.zip_ssh

    1. **密钥生成**:用户通常使用`ssh-keygen`命令生成一对密钥,公钥放在服务器上,私钥保留在本地。 2. **公钥认证**:将公钥添加到服务器的`~/.ssh/authorized_keys`文件中,实现无密码登录。 3. **配置文件**:SSH...

    linux SSh工具

    10. **安全实践**: 遵循最佳安全实践,如禁用root用户直接通过SSH登录,限制无效尝试,启用SSH日志监控,定期更新SSH版本以防止已知漏洞利用。 总之,SSH工具在Linux系统中扮演着至关重要的角色,不仅提供了安全的...

    ssh-demo.rar_DEMO_ssh demo

    保持SSH的最新版本,定期更新密钥,限制无效尝试的次数,使用强密码或密钥,以及监控SSH活动,都是提高SSH安全性的关键措施。 这个"ssh demo"可能包含了上述概念的实践示例,比如配置文件、命令行用法、端口转发等...

    慕课SSH系统工程

    用户可以通过`ssh-keygen`命令生成一对公钥和私钥,公钥部署在远程服务器上,私钥保留在本地。这种方式比传统的密码认证更安全,因为即使黑客获取了公钥,没有私钥也无法登录。 **三、SSH免密登录** 通过将本地公钥...

    SSH搭建环境讲解

    在Java开发环境中,SSH通常指的是Spring、Struts和Hibernate这三个开源框架的组合,它们一起构建了强大的企业级Web应用解决方案。然而,这里的"SSH搭建环境讲解"可能指的是设置SSH连接,以便安全地管理和操作远程...

    ssh代码演示

    10. **安全性与最佳实践**:保持SSH版本更新,限制无效的登录尝试,使用防火墙限制SSH的访问源,以及定期更换私钥都是提高SSH安全性的关键。 以上就是SSH的基本使用和代码演示中的常见步骤。通过熟练掌握这些操作,...

    ssh0adfd1.rarssh0adfd1.rarssh0adfd1.rarssh0adfd1.rarssh0adfd1.rarssh0adfd1.rarssh0adfd1.rarssh0adfd1.rarssh0adfd1.rarssh0adfd1.rarssh0adfd1.rarssh0adfd1.rar

    7. **SSH安全**:为了增强安全性,应定期更换SSH密钥对,限制无效尝试次数,禁用密码登录,启用防火墙规则限制SSH访问,并考虑使用更安全的SSH版本或补丁。 8. **SSH工具**:有许多开源工具如`ssh`, `scp`, `sftp`,...

    CentOS系统公钥登陆.docx

    使用SSH客户端的密钥生成工具(例如OpenSSH的ssh-keygen)在本地生成一对公钥和私钥。通常,私钥(如id_rsa)保存在用户主目录的.ssh目录下,而公钥(如id_rsa.pub)则与之对应。 3. **生成公钥**: 在生成公钥的...

    S2S2H3 环境搭建

    6. **配置SSH客户端**:在本地开发机器上配置SSH客户端,如ssh-keygen用于生成密钥对,ssh-copy-id用于将公钥复制到远程服务器。 7. **环境变量与路径设置**:确保所有必要的工具路径正确,如JAVA_HOME, PATH等,...

    openSSH8.0p1.tar.gz

    6. **验证升级**: 使用 `sshd -T` 或 `ssh-keygen -Q -l` 命令检查新版本是否正确安装,并通过 `ssh -V` 查看客户端的版本信息。 7. **安全检查**: 安装完成后,建议进行安全审计,确保所有配置符合最佳实践,如...

    OpenSSH-Win32

    4. ssh-keygen:用于生成公钥/私钥对,这是SSH认证的核心部分。 5. ssh-agent:管理用户的密钥,使得用户在多个会话间无需重复输入密码。 在华为交换机的场景中,可能需要以下操作步骤: 1. **安装OpenSSH-Win32**...

    openssh8.6p1.zip

    用户可以通过`ssh-keygen`命令生成新的密钥对,并将其配置到服务器和客户端。 在日常运维中,安全策略的实施也非常重要。例如,定期更换密钥、限制无效尝试的次数(通过`MaxAuthTries`配置项)、使用防火墙...

    openssh9.0p1的rpm文件

    4. `openssh-keygen`: 用于生成密钥对,这是SSH协议中的身份验证基础。 5. `openssh-pkcs11`: 支持使用PKCS#11接口的硬件令牌进行认证。 6. `openssl`: OpenSSH依赖于OpenSSL库来处理加密和安全通信。 在安装这些...

Global site tag (gtag.js) - Google Analytics