Ubuntu
儘管有所有可用的資訊,但我對無密碼登錄感到困惑。幫助?
所以我有我的家用電腦和一台伺服器。我希望伺服器能夠在沒有密碼的情況下通過 SSH 連接到我的家用電腦。我遵循了各種教程,並且可以在沒有密碼的情況下從家裡ssh到伺服器。一切正常。當我嘗試反轉程序並從伺服器ssh到家庭時,我收到**權限被拒絕(公鑰)**錯誤。我可以使用密碼登錄兩台機器就好了。
詳細嘗試的相關位如下:
debug1: Found key in /root/.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: SSH2_MSG_SERVICE_REQUEST sent debug1: SSH2_MSG_SERVICE_ACCEPT received debug1: Authentications that can continue: publickey,keyboard-interactive debug1: Next authentication method: publickey debug1: Trying private key: /root/.ssh/identity debug1: Offering public key: /root/.ssh/id_rsa debug1: Authentications that can continue: publickey,keyboard-interactive debug1: Trying private key: /root/.ssh/id_dsa debug1: Next authentication method: keyboard-interactive debug1: Authentications that can continue: publickey,keyboard-interactive debug1: No more authentication methods to try. Permission denied (publickey,keyboard-interactive).
我在家用 PC 上的 /etc/ssh/sshd_config 文件如下所示:
# 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 #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 ~/.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 yes # Change to yes to enable challenge-response passwords (beware issues with # some PAM modules and threads) ChallengeResponseAuthentication yes # Change to no to disable tunnelled clear text passwords PasswordAuthentication no # 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 no
家用 PC 執行 Ubuntu,伺服器是 CentOS。
您的 AuthorizedKeysFile 行應為
AuthorizedKeysFile .ssh/authorized_keys
. 還要確保您的 .ssh 目錄700
的權限是 ,並且您的 authorized_keys 文件的權限是600
.
您是否在伺服器上創建了一個使用者密鑰,然後將該公鑰複製到您的 home box 上的 .ssh/authorized_keys 中?
更簡單的選擇是使用通常的“ssh-keygen …”命令創建您的密鑰,然後使用“ssh-copy-id”命令將公鑰移動到另一台機器上。
ssh-keygen (follow the prompts) ssh-copy-id -i ~/.ssh/id_rsa.pub me@home_system
當然,將 id_rsa.pub 更改為您選擇的任何關鍵方法(ssh-keygen 的命令行選項)。
請記住,ssh 密鑰是一種方式……從這裡到那裡。因此,如果您想以另一種方式使用無密碼登錄,您也必須進行設置。