解决远程服务器ssh登陆慢等问题

刚开始用的时候,总会遇到输入了用户名以后等半天才出输入密码的框,很是急人。这是dns反查造成的。
解决方法如下:
1)编辑 /etc/ssh/sshd_conf , 将 #UseDNS yes 取消注释,设为no ,重启sshd
2)编辑/etc/hosts,将自己的ip以及对应的主机名加进去

下面是我测试的

 ssh -v  192.168.88.88

 

  1. OpenSSH_4.3p2, OpenSSL 0.9.8e-fips-rhel5 01 Jul 2008 
  2. debug1: Reading configuration data /etc/ssh/ssh_config 
  3. debug1: Applying options for * 
  4. debug1: Connecting to 192.168.88.88 [192.168.88.88] port 22. 
  5. debug1: Connection established. 
  6. debug1: permanently_set_uid: 0/0 
  7. debug1: identity file /root/.ssh/identity type -1 
  8. debug1: identity file /root/.ssh/id_rsa type -1 
  9. debug1: identity file /root/.ssh/id_dsa type -1 
  10. debug1: loaded 3 keys 
  11. debug1: Remote protocol version 2.0, remote software version OpenSSH_4.3 
  12. debug1: match: OpenSSH_4.3 pat OpenSSH* 
  13. debug1: Enabling compatibility mode for protocol 2.0 
  14. debug1: Local version string SSH-2.0-OpenSSH_4.3 
  15. debug1: SSH2_MSG_KEXINIT sent 
  16. debug1: SSH2_MSG_KEXINIT received 
  17. debug1: kex: server->client aes128-ctr hmac-md5 none 
  18. debug1: kex: client->server aes128-ctr hmac-md5 none 
  19. debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent 
  20. debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP 
  21. debug1: SSH2_MSG_KEX_DH_GEX_INIT sent 
  22. debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY 
  23. debug1: Host '192.168.88.88' is known and matches the RSA host key. 
  24. debug1: Found key in /root/.ssh/known_hosts:6 
  25. debug1: ssh_rsa_verify: signature correct 
  26. debug1: SSH2_MSG_NEWKEYS sent 
  27. debug1: expecting SSH2_MSG_NEWKEYS 
  28. debug1: SSH2_MSG_NEWKEYS received 
  29. debug1: SSH2_MSG_SERVICE_REQUEST sent 
  30. debug1: SSH2_MSG_SERVICE_ACCEPT received 
  31. debug1: Authentications that can continue: publickey,gssapi-with-mic,password 
  32. debug1: Next authentication method: gssapi-with-mic 
  33. debug1: Unspecified GSS failure.  Minor code may provide more information 
  34. No credentials cache found 
  35. debug1: Unspecified GSS failure.  Minor code may provide more information 
  36. No credentials cache found 
  37. debug1: Unspecified GSS failure.  Minor code may provide more information 
  38. No credentials cache found 
  39. debug1: Next authentication method: publickey 
  40. debug1: Trying private key: /root/.ssh/identity 
  41. debug1: Trying private key: /root/.ssh/id_rsa 
  42. debug1: Trying private key: /root/.ssh/id_dsa 
  43. debug1: Next authentication method: password 

 可以看到登录过程卡在GSS这一块。使用ssh  -o GSSAPIAuthentication=no 10.150.10.2登录,马上就跳出输入密码。 解决方法: 修改本地中的/etc/ssh/ssh_config或者远程服务器端的/etc/ssh/sshd_config,把参数GSSAPIAuthentication 修改为no就可以了。 GSSAPIAuthentication选项的作用:是否允许使用基于 GSSAPI 的用户认证。默认为yes 附上/etc/ssh/sshd.config 的参数解释 # 1. 关于 SSH Server 的整体设定,包含使用的 port 啦,以及使用的密码演算方式 

    1. Port 22          # SSH 预设使用 22 这个 port,您也可以使用多的 port ! 
    2.               # 亦即重复使用 port 这个设定项目即可! 
    3. Protocol 2,1        # 选择的 SSH 协议版本,可以是 1 也可以是 2 , 
    4.               # 如果要同时支持两者,就必须要使用 2,1 这个分隔了! 
    5. #ListenAddress 0.0.0.0   # 监听的主机适配卡!举个例子来说,如果您有两个 IP, 
    6.               # 分别是 192.168.0.100 及 192.168.2.20 ,那么只想要 
    7.               # 开放 192.168.0.100 时,就可以写如同下面的样式: 
    8. ListenAddress 192.168.0.100          # 只监听来自 192.168.0.100 这个 IP 的SSH联机。 
    9.                    # 如果不使用设定的话,则预设所有接口均接受 SSH 
    10. PidFile /var/run/sshd.pid      # 可以放置 SSHD 这个 PID 的档案!左列为默认值 
    11. LoginGraceTime 600     # 当使用者连上 SSH server 之后,会出现输入密码的画面, 
    12.               # 在该画面中,在多久时间内没有成功连上 SSH server , 
    13.               # 就断线!时间为秒! 
    14. Compression yes      # 是否可以使用压缩指令?当然可以?! 
    15.   
    16. # 2. 说明主机的 Private Key 放置的档案,预设使用下面的档案即可! 
    17. HostKey /etc/ssh/ssh_host_key    # SSH version 1 使用的私钥 
    18. HostKey /etc/ssh/ssh_host_rsa_key  # SSH version 2 使用的 RSA 私钥 
    19. HostKey /etc/ssh/ssh_host_dsa_key  # SSH version 2 使用的 DSA 私钥 
    20.  
    21. # 2.1 关于 version 1 的一些设定! 
    22. KeyRegenerationInterval 3600     # 由前面联机的说明可以知道, version 1 会使用  
    23.                    # server 的 Public Key ,那么如果这个 Public  
    24.                    # Key 被偷的话,岂不完蛋?所以需要每隔一段时间 
    25.                    # 来重新建立一次!这里的时间为秒! 
    26. ServerKeyBits 768           # 没错!这个就是 Server key 的长度! 
    27. # 3. 关于登录文件的讯息数据放置与 daemon 的名称! 
    28. SyslogFacility AUTH         # 当有人使用 SSH 登入系统的时候,SSH会记录资 
    29.                    # 讯,这个信息要记录在什么 daemon name 底下? 
    30.                    # 预设是以 AUTH 来设定的,即是 /var/log/secure 
    31.                    # 里面!什么?忘记了!回到 Linux 基础去翻一下 
    32.                    # 其它可用的 daemon name 为:DAEMON,USER,AUTH, 
    33.                    # LOCAL0,LOCAL1,LOCAL2,LOCAL3,LOCAL4,LOCAL5, 
    34. LogLevel INFO            # 登录记录的等级!嘿嘿!任何讯息! 
    35.                    # 同样的,忘记了就回去参考! 
    36. # 4. 安全设定项目!极重要! 
    37. # 4.1 登入设定部分 
    38. PermitRootLogin no     # 是否允许 root 登入!预设是允许的,但是建议设定成 no! 
    39. UserLogin no        # 在 SSH 底下本来就不接受 login 这个程序的登入! 
    40. StrictModes yes      # 当使用者的 host key 改变之后,Server 就不接受联机, 
    41.               # 可以抵挡部分的木马程序! 
    42. #RSAAuthentication yes   # 是否使用纯的 RSA 认证!?仅针对 version 1 ! 
    43. PubkeyAuthentication yes  # 是否允许 Public Key ?当然允许啦!只有 version 2 
    44. AuthorizedKeysFile      .ssh/authorized_keys 
    45.               # 上面这个在设定若要使用不需要密码登入的账号时,那么那个 
    46.               # 账号的存放档案所在档名! 
    47. # 4.2 认证部分 
    48. RhostsAuthentication no  # 本机系统不止使用 .rhosts ,因为仅使用 .rhosts 太 
    49.               # 不安全了,所以这里一定要设定为 no ! 
    50. IgnoreRhosts yes      # 是否取消使用 ~/.ssh/.rhosts 来做为认证!当然是! 
    51. RhostsRSAAuthentication no # 这个选项是专门给 version 1 用的,使用 rhosts 档案在 
    52.               # /etc/hosts.equiv配合 RSA 演算方式来进行认证!不要使用 
    53. HostbasedAuthentication no # 这个项目与上面的项目类似,不过是给 version 2 使用的! 
    54. IgnoreUserKnownHosts no  # 是否忽略家目录内的 ~/.ssh/known_hosts 这个档案所记录 
    55.               # 的主机内容?当然不要忽略,所以这里就是 no 啦! 
    56. PasswordAuthentication yes # 密码验证当然是需要的!所以这里写 yes ?! 
    57. PermitEmptyPasswords no  # 若上面那一项如果设定为 yes 的话,这一项就最好设定 
    58.               # 为 no ,这个项目在是否允许以空的密码登入!当然不许! 
    59. ChallengeResponseAuthentication yes  # 挑战任何的密码认证!所以,任何 login.conf  
    60.                    # 规定的认证方式,均可适用! 
    61. #PAMAuthenticationViaKbdInt yes      # 是否启用其它的 PAM 模块!启用这个模块将会 
    62.                    # 导致 PasswordAuthentication 设定失效! 
    63.   
    64. # 4.3 与 Kerberos 有关的参数设定!因为我们没有 Kerberos 主机,所以底下不用设定! 
    65. #KerberosAuthentication no 
    66. #KerberosOrLocalPasswd yes 
    67. #KerberosTicketCleanup yes 
    68. #KerberosTgtPassing no 
    69.   
    70. # 4.4 底下是有关在 X-Window 底下使用的相关设定! 
    71. X11Forwarding yes 
    72. #X11DisplayOffset 10 
    73. #X11UseLocalhost yes 
    74. # 4.5 登入后的项目: 
    75. PrintMotd no              # 登入后是否显示出一些信息呢?例如上次登入的时间、地点等 
    76.              # 等,预设是 yes ,但是,如果为了安全,可以考虑改为 no ! 
    77. PrintLastLog yes     # 显示上次登入的信息!可以啊!预设也是 yes ! 
    78. KeepAlive yes       # 一般而言,如果设定这项目的话,那么 SSH Server 会传送 
    79.              # KeepAlive 的讯息给 Client 端,以确保两者的联机正常! 
    80.              # 在这个情况下,任何一端死掉后, SSH 可以立刻知道!而不会 
    81.              # 有僵尸程序的发生! 
    82. UsePrivilegeSeparation yes # 使用者的权限设定项目!就设定为 yes 吧! 
    83. MaxStartups 10      # 同时允许几个尚未登入的联机画面?当我们连上 SSH , 
    84.              # 但是尚未输入密码时,这个时候就是我们所谓的联机画面啦! 
    85.              # 在这个联机画面中,为了保护主机,所以需要设定最大值, 
    86.              # 预设最多十个联机画面,而已经建立联机的不计算在这十个当中 
    87. # 4.6 关于使用者抵挡的设定项目: 
    88. DenyUsers *        # 设定受抵挡的使用者名称,如果是全部的使用者,那就是全部 
    89.              # 挡吧!若是部分使用者,可以将该账号填入!例如下列! 
    90. DenyUsers test 
    91. DenyGroups test      # 与 DenyUsers 相同!仅抵挡几个群组而已! 
    92. # 5. 关于 SFTP 服务的设定项目! 
    93. Subsystem       sftp    /usr/lib/ssh/sftp-server

转载于:https://www.cnblogs.com/centos-python/articles/8522479.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值