ssh-keygen 问题

ssh-keygen 问题

我已经使用 keygen 配置了 ssh-key,以进行无密码身份验证,如以下链接所示http://rcsg-gsir.imsb-dsgi.nrc-cnrc.gc.ca/documents/internet/node31.html 无论我做什么,它都会不断询问密码。我已经在 Google 上搜索了很多关于此问题的信息,并且我已经将 .ssh 的权限设置为 700,将 authorized_keys 文件的权限设置为 600。我在 /etc/ssh/sshd_config 文件中更改了以下内容

 ChallengeResponseAuthentication no
 PasswordAuthentication no

重新启动 ssh,重新启动系统,检查 ssh-agent pid 并且它正在运行。这仍然要求输入密码,如果有人可以解释一下,请告诉我。

ssh -v 输出

 OpenSSH_4.3p2, OpenSSL 0.9.8b 04 May 2006
 debug1: Reading configuration data /etc/ssh/ssh_config
 debug1: Applying options for *
 debug1: Connecting to 174.3.16.182 [174.3.16.182] port 22.
 debug1: Connection established.
 debug1: permanently_set_uid: 0/0
 debug1: identity file /root/.ssh/identity type -1
 debug1: identity file /root/.ssh/id_rsa type -1
 debug1: identity file /root/.ssh/id_dsa type 2
 debug1: loaded 3 keys
 debug1: Remote protocol version 2.0, remote software version OpenSSH_4.3
 debug1: match: OpenSSH_4.3 pat OpenSSH*
 debug1: Enabling compatibility mode for protocol 2.0
 debug1: Local version string SSH-2.0-OpenSSH_4.3
 debug1: SSH2_MSG_KEXINIT sent
 debug1: SSH2_MSG_KEXINIT received
 debug1: kex: server->client aes128-cbc hmac-md5 none
 debug1: kex: client->server aes128-cbc hmac-md5 none
 debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
 debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
 debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
 debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
 The authenticity of host '174.3.16.182 (174.3.16.182)' can't be established.
 RSA key fingerprint is ca:85:11:08:550:65:7b:8b:5c:73:62:94:38:59:65:.
 Are you sure you want to continue connecting (yes/no)? yes
 Warning: Permanently added '174.3.16.182' (RSA) to the list of known hosts.
 debug1: ssh_rsa_verify: signature correct
 debug1: SSH2_MSG_NEWKEYS sent
 debug1: expecting SSH2_MSG_NEWKEYS
 debug1: SSH2_MSG_NEWKEYS received
 debug1: SSH2_MSG_SERVICE_REQUEST sent
 debug1: SSH2_MSG_SERVICE_ACCEPT received
 debug1: Authentications that can continue: publickey,password
 debug1: Next authentication method: publickey
 debug1: Trying private key: /root/.ssh/identity
 debug1: Trying private key: /root/.ssh/id_rsa
 debug1: Offering public key: /root/.ssh/id_dsa
 debug1: Authentications that can continue: publickey,password
 debug1: Next authentication method: password
 [email protected]'s password:

编辑:这是远程机器上的 sshd_config 文件

     #       $OpenBSD: sshd_config,v 1.73 2005/12/06 22:38:28 reyk Exp $

     # This is the sshd server system-wide configuration file.  See
     # sshd_config(5) for more information.

     # This sshd was compiled with PATH=/usr/local/bin:/bin:/usr/bin

     # The strategy used for options in the default sshd_config shipped with
     # OpenSSH is to specify options with their default value where
     # possible, but leave them commented.  Uncommented options change a
     # default value.

     #Port 22
     #Protocol 2,1
     Protocol 2
     #AddressFamily any
     #ListenAddress 0.0.0.0
     #ListenAddress ::

     # HostKey for protocol version 1
     #HostKey /etc/ssh/ssh_host_key
     # HostKeys for protocol version 2
     #HostKey /etc/ssh/ssh_host_rsa_key
     #HostKey /etc/ssh/ssh_host_dsa_key

     # Lifetime and size of ephemeral version 1 server key
     #KeyRegenerationInterval 1h
     #ServerKeyBits 768

     # Logging
     # obsoletes QuietMode and FascistLogging
     #SyslogFacility AUTH
     SyslogFacility AUTHPRIV
     #LogLevel INFO

     # Authentication:

     #LoginGraceTime 2m
     #PermitRootLogin yes
     #StrictModes yes
     #MaxAuthTries 6
     RSAAuthentication yes
     PubkeyAuthentication yes
     #AuthorizedKeysFile     /root/.ssh/authorized_keys

     # For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
     #RhostsRSAAuthentication no
     # similar for protocol version 2
     #HostbasedAuthentication no
     # Change to yes if you don't trust ~/.ssh/known_hosts for
     # RhostsRSAAuthentication and HostbasedAuthentication
     #IgnoreUserKnownHosts no
     # Don't read the user's ~/.rhosts and ~/.shosts files
     #IgnoreRhosts yes

     # To disable tunneled clear text passwords, change to no here!
     #PasswordAuthentication yes
     #PermitEmptyPasswords no
     PasswordAuthentication yes

     # Change to no to disable s/key passwords
     #ChallengeResponseAuthentication yes
     ChallengeResponseAuthentication no

     # Kerberos options
     #KerberosAuthentication no
     #KerberosOrLocalPasswd yes
     #KerberosTicketCleanup yes
     #KerberosGetAFSToken no

     # GSSAPI options
     GSSAPIAuthentication no
     #GSSAPIAuthentication yes
     #GSSAPICleanupCredentials yes
     GSSAPICleanupCredentials yes
    # Set this to 'yes' to enable PAM authentication, account processing,
     # and session processing. If this is enabled, PAM authentication will
     # be allowed through the ChallengeResponseAuthentication mechanism.
     # Depending on your PAM configuration, this may bypass the setting of
     # PasswordAuthentication, PermitEmptyPasswords, and
     # "PermitRootLogin without-password". If you just want the PAM account and
     # session checks to run without PAM authentication, then enable this but set
     # ChallengeResponseAuthentication=no
     #UsePAM no
     UsePAM yes

     # Accept locale-related environment variables
     AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES
     AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT
     AcceptEnv LC_IDENTIFICATION LC_ALL
     #AllowTcpForwarding yes
     #GatewayPorts no
     #X11Forwarding no
     X11Forwarding yes
     #X11DisplayOffset 10
     #X11UseLocalhost yes
     #PrintMotd yes
     #PrintLastLog yes
     #TCPKeepAlive yes
     #UseLogin no
     #UsePrivilegeSeparation yes
     #PermitUserEnvironment no
     #Compression delayed
     #ClientAliveInterval 0
     #ClientAliveCountMax 3
     #ShowPatchLevel no
     #UseDNS yes
     #PidFile /var/run/sshd.pid
     #MaxStartups 10
     #PermitTunnel no
     #ChrootDirectory none

     # no default banner path
     #Banner /some/path

     # override default of no subsystems
     Subsystem       sftp    /usr/libexec/openssh/sftp-server

这是生成密钥的 sshd_config 文件

  # Set this to 'yes' to enable PAM authentication, account processing,
  # and session processing. If this is enabled, PAM authentication will
  # be allowed through the ChallengeResponseAuthentication mechanism.
  # Depending on your PAM configuration, this may bypass the setting of
  # PasswordAuthentication, PermitEmptyPasswords, and
  # "PermitRootLogin without-password". If you just want the PAM account and
  # session checks to run without PAM authentication, then enable this but set
  # ChallengeResponseAuthentication=no
  #UsePAM no
  UsePAM yes

  # Accept locale-related environment variables
  AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES
  AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT
  AcceptEnv LC_IDENTIFICATION LC_ALL
  #AllowTcpForwarding yes
  #GatewayPorts no
  #X11Forwarding no
  X11Forwarding yes
  #X11DisplayOffset 10
  #X11UseLocalhost yes
  #PrintMotd yes
  #PrintLastLog yes
  #TCPKeepAlive yes
  #UseLogin no
  #UsePrivilegeSeparation yes
  #PermitUserEnvironment no
  #Compression delayed
  #ClientAliveInterval 0
  #ClientAliveCountMax 3
  #ShowPatchLevel no
  #UseDNS yes
  #PidFile /var/run/sshd.pid
  #MaxStartups 10
  #PermitTunnel no

  # no default banner path
  #Banner /some/path

  # override default of no subsystems
  Subsystem       sftp    /usr/libexec/openssh/sftp-server

答案1

设置 ssh 密钥最简单的方法是使用命令

ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected]

如果这样也失败了,那么你的 sshd_config 中肯定存在一些异常,我们需要处理。

编辑:所以,毕竟是你的 sshd_config 出了问题。

改变这个:

 #PermitRootLogin yes

成为

 PermitRootLogin without-password

因此只允许对 root 进行密钥身份验证。或者,如果您只想运行特定命令,这将forced-commands-only是更好的选择,但在进行此操作之前,请先使用该without-password选项。

无论如何,更改之后重新启动你的 sshd 并查看一切如何开始工作!

答案2

首先,您确定允许您通过 ssh 进入 root 吗?(提示:检查服务器上的 sshd_config 文件)。

其次,您是否以用户身份登录并使用了sudo其他方式冒充他人?也许您只是从错误的 $USER 启动了 ssh!

答案3

尝试增加生成的密钥的大小。使用以下命令:

ssh-keygen -t rsa -b 4096

然后,将公钥复制到远程机器(.ssh/authorized_keys)。

答案4

当您执行 ssh-keygen 时,系统会要求您输入密码,或者按“enter”键表示无密码。我总是按“enter”键。生成密钥(公钥和私钥)后,将公钥复制到相关机器。然后执行“cat”key.pub(或生成的任何内容)>> .ssh/authorized_keys。我经常从一台机器 ssh 到另一台机器,而无需输入密码。我运行 centos5.5、debian 和 slackware。

艾伦

相关内容