我正在嘗試使用以下命令將我的 Windows 10 電腦設定為 ssh 伺服器Win32-OpenSSH。伺服器是網域的一部分,所以我使用命令
ssh -i ~/.ssh/id_rsa -l user@domain ip_address
從我的 ssh 客戶端連線。
這會出現錯誤「權限被拒絕(公鑰,鍵盤互動)」。在伺服器端,日誌顯示
sshd:來自 ip_address 連接埠 59676 的使用者 user@domain 無效
sshd:連線被無效使用者 user@domain ip_address 連接埠 59676 [preauth] 關閉
我還嘗試了 ssh 命令的以下變體
ssh -i ~/.ssh/id_rsa domain/user@ip_address
嘗試從客戶端連線。我收到“連接由 ip_address 連接埠 22 重置”錯誤。
如果我查看伺服器端的日誌,它會顯示:
sshd:錯誤:lookup_principal_name:使用者“域\使用者”的使用者主體名稱查找失敗(顯式:5,隱式:5)”
sshd:錯誤:get_user_token - 無法在第二次嘗試為使用者網域\使用者產生令牌
sshd:致命:ga_init,無法解析用戶網域\用戶
我該如何解決這個錯誤?
細節
在伺服器(Windows 10)端:
whoami
確認我的用戶名是網域\用戶
我只想使用公鑰身份驗證,因此我將 sshd_config 中的權限設為
PubkeyAuthentication yes
PasswordAuthentication no
所有其他設定均為預設設定。完整的 sshd_config 檔案如下
# This is the sshd server system-wide configuration file. See
# sshd_config(5) for more information.
# 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.
#Port 22
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::
#HostKey __PROGRAMDATA__/ssh/ssh_host_rsa_key
#HostKey __PROGRAMDATA__/ssh/ssh_host_dsa_key
#HostKey __PROGRAMDATA__/ssh/ssh_host_ecdsa_key
#HostKey __PROGRAMDATA__/ssh/ssh_host_ed25519_key
# Ciphers and keying
#RekeyLimit default none
# Logging
#SyslogFacility AUTH
#LogLevel INFO
# Authentication:
#LoginGraceTime 2m
#PermitRootLogin prohibit-password
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10
#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
# For this to work you will also need host keys in %programData%/ssh/ssh_known_hosts
#HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# 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
PubkeyAuthentication yes
PasswordAuthentication no
# GSSAPI options
#GSSAPIAuthentication no
#AllowAgentForwarding yes
#AllowTcpForwarding yes
#GatewayPorts no
#PermitTTY yes
#PrintMotd yes
#PrintLastLog yes
#TCPKeepAlive yes
#UseLogin no
#PermitUserEnvironment no
#ClientAliveInterval 0
#ClientAliveCountMax 3
#UseDNS no
#PidFile /var/run/sshd.pid
#MaxStartups 10:30:100
#PermitTunnel no
#ChrootDirectory none
#VersionAddendum none
# no default banner path
#Banner none
# override default of no subsystems
Subsystem sftp sftp-server.exe
# Example of overriding settings on a per-user basis
#Match User anoncvs
# AllowTcpForwarding no
# PermitTTY no
# ForceCommand cvs server
Match Group administrators
AuthorizedKeysFile __PROGRAMDATA__/ssh/administrators_authorized_keys
我將 id_rsa.pub 附加到 C:\Users\user\.ssh 目錄中的authorized_keys 檔案中。icacls .\authorized_keys
回報
C:\Users\user\\.ssh\authorized_keys NT AUTHORITY\SYSTEM:(I)(F)
BUILTIN\Administrators:(I)(F)
DOMAIN\user:(I)(F)
在客戶端(Ubuntu 20.04.3)端:
~/.ssh/id_rsa 具有以下權限
-rw------- 1 ubuntu ubuntu 2655 Dec 30 18:16 id_rsa
-rw-r--r-- 1 ubuntu ubuntu 576 Dec 30 18:16 id_rsa.pub
答案1
Match Group administrators
AuthorizedKeysFile __PROGRAMDATA__/ssh/administrators_authorized_keys
將這些行設為註解行