Linux 无法在mac(约塞米蒂)和服务器(ubuntu)之间配对ssh密钥

Linux 无法在mac(约塞米蒂)和服务器(ubuntu)之间配对ssh密钥,linux,macos,ubuntu,ssh,Linux,Macos,Ubuntu,Ssh,好吧,我知道这个问题经常被问到。然而,我看了看,并尝试了每一个没有成功。以下是我所做工作的完整步骤: 我使用以下命令创建了一对公钥和私钥,但没有任何密码短语密码: 命令 在我的.ssh文件夹中,我检查以确保权限正常,仍然在我的mac上 权限 和.ssh文件夹: drwx------ 7 etienne staff 238 30 jan 10:25 .ssh 然后,我在服务器上验证了/etc/ssh/sshd_-config中的sshd_-config是否有这些行 配置文件 完

好吧,我知道这个问题经常被问到。然而,我看了看,并尝试了每一个没有成功。以下是我所做工作的完整步骤:

  • 我使用以下命令创建了一对公钥和私钥,但没有任何密码短语密码:
  • 命令

  • 在我的.ssh文件夹中,我检查以确保权限正常,仍然在我的mac上
  • 权限

    和.ssh文件夹:

    drwx------    7 etienne  staff      238 30 jan 10:25 .ssh
    
  • 然后,我在服务器上验证了
    /etc/ssh/sshd_-config
    中的sshd_-config是否有这些行
  • 配置文件

    完整的sshd_配置位于末尾

  • 在服务器上,我将位于mac上的id_rsa.pub中的公钥复制到服务器上
    /home/imatech/.ssh/

  • 我的服务器上的授权密钥文件的权限为:

  • 许可

  • .ssh文件夹的权限为:
  • 许可

  • 现在,在我的mac上,我尝试访问imatech@server.com使用以下命令:
    ssh-vimatech@server.com
    ,无法使用我的私钥进行身份验证:
  • 命令:

    mac的sshd\u配置

    #   $OpenBSD: sshd_config,v 1.89 2013/02/06 00:20:42 dtucker Exp $
    
    # This is the sshd server system-wide configuration file.  See
    # sshd_config(5) for more information.
    
    # This sshd was compiled with PATH=/usr/bin:/bin:/usr/sbin:/sbin
    
    # 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 override the
    # default value.
    
    # See sshd_config(5) for details on setting the Port and Listen values on Mac OS X
    #Port 22
    #AddressFamily any
    #ListenAddress 0.0.0.0
    #ListenAddress ::
    
    # The default requires explicit activation of protocol 1
    #Protocol 2
    
    # 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
    #HostKey /etc/ssh/ssh_host_ecdsa_key
    
    # Lifetime and size of ephemeral version 1 server key
    #KeyRegenerationInterval 1h
    #ServerKeyBits 1024
    
    # Logging
    # obsoletes QuietMode and FascistLogging
    SyslogFacility AUTHPRIV
    #LogLevel INFO
    
    # Authentication:
    
    #LoginGraceTime 2m
    #PermitRootLogin yes
    #StrictModes yes
    #MaxAuthTries 6
    #MaxSessions 10
    
    #RSAAuthentication yes
    #PubkeyAuthentication yes
    
    # The default is to check both .ssh/authorized_keys and .ssh/authorized_keys2
    # but this is overridden so installations will only check .ssh/authorized_keys
    AuthorizedKeysFile  .ssh/authorized_keys
    
    #AuthorizedPrincipalsFile none
    
    #AuthorizedKeysCommand none
    #AuthorizedKeysCommandUser nobody
    
    # 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 both PasswordAuthentication and
    # ChallengeResponseAuthentication must be set to "no".
    #PasswordAuthentication no
    #PermitEmptyPasswords no
    
    # Change to no to disable s/key passwords
    #ChallengeResponseAuthentication yes
    
    # Kerberos options
    #KerberosAuthentication no
    #KerberosOrLocalPasswd yes
    #KerberosTicketCleanup yes
    
    # GSSAPI options
    #GSSAPIAuthentication no
    #GSSAPICleanupCredentials yes
    #GSSAPIStrictAcceptorCheck yes
    #GSSAPIKeyExchange no
    
    # 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 and
    # PasswordAuthentication.  Depending on your PAM configuration,
    # PAM authentication via ChallengeResponseAuthentication may bypass
    # the setting of "PermitRootLogin without-password".
    # If you just want the PAM account and session checks to run without
    # PAM authentication, then enable this but set PasswordAuthentication
    # and ChallengeResponseAuthentication to 'no'.
    # Also, PAM will deny null passwords by default.  If you need to allow
    # null passwords, add the " nullok" option to the end of the
    # securityserver.so line in /etc/pam.d/sshd.
    #UsePAM yes
    
    #AllowAgentForwarding yes
    #AllowTcpForwarding yes
    #GatewayPorts no
    #X11Forwarding no
    #XauthLocation xauth # Default is to search $PATH (set by launchd(8)).  It is recommended that a full path be provided.
    #X11DisplayOffset 10
    #X11UseLocalhost yes
    #PrintMotd yes
    #PrintLastLog yes
    #TCPKeepAlive yes
    #UseLogin no
    UsePrivilegeSeparation sandbox      # Default for new installations.
    #PermitUserEnvironment no
    #Compression delayed
    #ClientAliveInterval 0
    #ClientAliveCountMax 3
    #UseDNS yes
    #PidFile /var/run/sshd.pid
    #MaxStartups 10:30:100
    #PermitTunnel no
    #ChrootDirectory none
    #VersionAddendum none
    
    # pass locale information
    AcceptEnv LANG LC_*
    
    # no default banner path
    #Banner none
    
    # override default of no subsystems
    Subsystem   sftp    /usr/libexec/sftp-server
    
    # Example of overriding settings on a per-user basis
    #Match User anoncvs
    #   X11Forwarding no
    #   AllowTcpForwarding no
    #   ForceCommand cvs server
    
    # XAuthLocation added by XQuartz (http://xquartz.macosforge.org)
    XAuthLocation /opt/X11/bin/xauth
    

    好的,我通过使用自制软件安装ssh副本id解决了这个问题:

    brew install ssh-copy-id
    
    然后,我简单地使用命令:

    ssh-copy-id -i id_rsa.pub imatech@server.com
    
    真奇怪

    -rw-r--r--  1 imatech imatech  172 Jan 30 10:19 authorized_keys 
    
    drwx------  2 imatech imatech  4096 Jan 30 10:19 .ssh
    
    OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011
    debug1: Reading configuration data /etc/ssh_config
    debug1: /etc/ssh_config line 20: Applying options for *
    debug1: /etc/ssh_config line 53: Applying options for *
    debug1: Connecting to ima-tech.ca [168.144.170.64] port 22.
    debug1: Connection established.
    debug1: identity file /Users/etienne/.ssh/id_rsa type 1
    debug1: identity file /Users/etienne/.ssh/id_rsa-cert type -1
    debug1: identity file /Users/etienne/.ssh/id_dsa type -1
    debug1: identity file /Users/etienne/.ssh/id_dsa-cert type -1
    debug1: Enabling compatibility mode for protocol 2.0
    debug1: Local version string SSH-2.0-OpenSSH_6.2
    debug1: Remote protocol version 2.0, remote software version OpenSSH_5.9p1 Debian-5ubuntu1.1
    debug1: match: OpenSSH_5.9p1 Debian-5ubuntu1.1 pat OpenSSH_5*
    debug1: SSH2_MSG_KEXINIT sent
    debug1: SSH2_MSG_KEXINIT received
    debug1: kex: server->client aes128-ctr hmac-md5 none
    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
    debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
    debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
    debug1: Server host key: RSA cf:45:23:53:41:6f:7b:3b:2d:1c:87:38:64:1f:5e:1b
    debug1: Host 'ima-tech.ca' is known and matches the RSA host key.
    debug1: Found key in /Users/etienne/.ssh/known_hosts:1
    debug1: ssh_rsa_verify: signature correct
    debug1: SSH2_MSG_NEWKEYS sent
    debug1: expecting SSH2_MSG_NEWKEYS
    debug1: SSH2_MSG_NEWKEYS received
    debug1: Roaming not allowed by server
    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: Offering RSA public key: /Users/etienne/.ssh/id_rsa
    debug1: Authentications that can continue: publickey,password
    debug1: Trying private key: /Users/etienne/.ssh/id_dsa
    debug1: Next authentication method: password
    
        # Package generated configuration file
        # See the sshd_config(5) manpage for details
    
        # What ports, IPs and protocols we listen for
        Port 22
        # Use these options to restrict which interfaces/protocols sshd will bind to
        #ListenAddress ::
        #ListenAddress 0.0.0.0
        Protocol 2
        # HostKeys for protocol version 2
        HostKey /etc/ssh/ssh_host_rsa_key
        HostKey /etc/ssh/ssh_host_dsa_key
        HostKey /etc/ssh/ssh_host_ecdsa_key
        #Privilege Separation is turned on for security
        UsePrivilegeSeparation yes
    
        # Lifetime and size of ephemeral version 1 server key
        KeyRegenerationInterval 3600
        ServerKeyBits 768
    
        # Logging
        SyslogFacility AUTH
        LogLevel INFO
    
        # Authentication:
        LoginGraceTime 120
        PermitRootLogin yes
        StrictModes yes
    
        RSAAuthentication yes
        PubkeyAuthentication yes
        AuthorizedKeysFile      %h/.ssh/authorized_keys
    
        # Don't read the user's ~/.rhosts and ~/.shosts files
        IgnoreRhosts yes
        # For this to work you will also need host keys in /etc/ssh_known_hosts
        RhostsRSAAuthentication no
        # similar for protocol version 2
        HostbasedAuthentication no
        # Uncomment if you don't trust ~/.ssh/known_hosts for RhostsRSAAuthentication
        #IgnoreUserKnownHosts yes
    
        # To enable empty passwords, change to yes (NOT RECOMMENDED)
        PermitEmptyPasswords no
    
        # Change to yes to enable challenge-response passwords (beware issues with
        # some PAM modules and threads)
        ChallengeResponseAuthentication no
    
        # Change to no to disable tunnelled clear text passwords
        #PasswordAuthentication yes
    
        # Kerberos options
        #KerberosAuthentication no
        #KerberosGetAFSToken no
        #KerberosOrLocalPasswd yes
        #KerberosTicketCleanup yes
    
        # GSSAPI options
        #GSSAPIAuthentication no
        #GSSAPICleanupCredentials yes
    
        X11Forwarding yes
        X11DisplayOffset 10
        PrintMotd no
        PrintLastLog yes
        TCPKeepAlive yes
        #UseLogin no
    
        #MaxStartups 10:30:60
        #Banner /etc/issue.net
    
        # Allow client to pass locale environment variables
        AcceptEnv LANG LC_*
    
        Subsystem sftp /usr/lib/openssh/sftp-server
    
        # 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 and
        # PasswordAuthentication.  Depending on your PAM configuration,
        # PAM authentication via ChallengeResponseAuthentication may bypass
        # the setting of "PermitRootLogin without-password".
        # If you just want the PAM account and session checks to run without
        # PAM authentication, then enable this but set PasswordAuthentication
        # and ChallengeResponseAuthentication to 'no'.
        UsePAM yes
    
    
        #Testing the use of the https to access the server via ssh behind proxy
        Port 2222
    
    #   $OpenBSD: sshd_config,v 1.89 2013/02/06 00:20:42 dtucker Exp $
    
    # This is the sshd server system-wide configuration file.  See
    # sshd_config(5) for more information.
    
    # This sshd was compiled with PATH=/usr/bin:/bin:/usr/sbin:/sbin
    
    # 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 override the
    # default value.
    
    # See sshd_config(5) for details on setting the Port and Listen values on Mac OS X
    #Port 22
    #AddressFamily any
    #ListenAddress 0.0.0.0
    #ListenAddress ::
    
    # The default requires explicit activation of protocol 1
    #Protocol 2
    
    # 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
    #HostKey /etc/ssh/ssh_host_ecdsa_key
    
    # Lifetime and size of ephemeral version 1 server key
    #KeyRegenerationInterval 1h
    #ServerKeyBits 1024
    
    # Logging
    # obsoletes QuietMode and FascistLogging
    SyslogFacility AUTHPRIV
    #LogLevel INFO
    
    # Authentication:
    
    #LoginGraceTime 2m
    #PermitRootLogin yes
    #StrictModes yes
    #MaxAuthTries 6
    #MaxSessions 10
    
    #RSAAuthentication yes
    #PubkeyAuthentication yes
    
    # The default is to check both .ssh/authorized_keys and .ssh/authorized_keys2
    # but this is overridden so installations will only check .ssh/authorized_keys
    AuthorizedKeysFile  .ssh/authorized_keys
    
    #AuthorizedPrincipalsFile none
    
    #AuthorizedKeysCommand none
    #AuthorizedKeysCommandUser nobody
    
    # 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 both PasswordAuthentication and
    # ChallengeResponseAuthentication must be set to "no".
    #PasswordAuthentication no
    #PermitEmptyPasswords no
    
    # Change to no to disable s/key passwords
    #ChallengeResponseAuthentication yes
    
    # Kerberos options
    #KerberosAuthentication no
    #KerberosOrLocalPasswd yes
    #KerberosTicketCleanup yes
    
    # GSSAPI options
    #GSSAPIAuthentication no
    #GSSAPICleanupCredentials yes
    #GSSAPIStrictAcceptorCheck yes
    #GSSAPIKeyExchange no
    
    # 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 and
    # PasswordAuthentication.  Depending on your PAM configuration,
    # PAM authentication via ChallengeResponseAuthentication may bypass
    # the setting of "PermitRootLogin without-password".
    # If you just want the PAM account and session checks to run without
    # PAM authentication, then enable this but set PasswordAuthentication
    # and ChallengeResponseAuthentication to 'no'.
    # Also, PAM will deny null passwords by default.  If you need to allow
    # null passwords, add the " nullok" option to the end of the
    # securityserver.so line in /etc/pam.d/sshd.
    #UsePAM yes
    
    #AllowAgentForwarding yes
    #AllowTcpForwarding yes
    #GatewayPorts no
    #X11Forwarding no
    #XauthLocation xauth # Default is to search $PATH (set by launchd(8)).  It is recommended that a full path be provided.
    #X11DisplayOffset 10
    #X11UseLocalhost yes
    #PrintMotd yes
    #PrintLastLog yes
    #TCPKeepAlive yes
    #UseLogin no
    UsePrivilegeSeparation sandbox      # Default for new installations.
    #PermitUserEnvironment no
    #Compression delayed
    #ClientAliveInterval 0
    #ClientAliveCountMax 3
    #UseDNS yes
    #PidFile /var/run/sshd.pid
    #MaxStartups 10:30:100
    #PermitTunnel no
    #ChrootDirectory none
    #VersionAddendum none
    
    # pass locale information
    AcceptEnv LANG LC_*
    
    # no default banner path
    #Banner none
    
    # override default of no subsystems
    Subsystem   sftp    /usr/libexec/sftp-server
    
    # Example of overriding settings on a per-user basis
    #Match User anoncvs
    #   X11Forwarding no
    #   AllowTcpForwarding no
    #   ForceCommand cvs server
    
    # XAuthLocation added by XQuartz (http://xquartz.macosforge.org)
    XAuthLocation /opt/X11/bin/xauth
    
    brew install ssh-copy-id
    
    ssh-copy-id -i id_rsa.pub imatech@server.com