macos - 在 MacOS 上无法 ssh 到 22 以外的本地主机端口
问题描述
我正在尝试使用 X11 从我大学的服务器转发到我的 PC。我必须 ssh 到跳转服务器,然后 ssh 到目标服务器。由于它在我的带有 XShell 和 XManager 的 Windows 设备上使用隧道运行良好,我尝试在我的 Mac 上使用ssh -Nf -L 8964:xx.xx.xx.xx:22 user@yy.yy.yy.yy
. 然后,当我尝试ssh 127.0.0.1 -p 8964 -v
像在 Windows 上那样在另一个终端窗口中使用命令时,它表明
OpenSSH_8.1p1, LibreSSL 2.7.3
debug1: Reading configuration data /Users/Lighter/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 47: Applying options for *
debug1: /etc/ssh/ssh_config line 51: Applying options for *
debug1: Connecting to 127.0.0.1 [127.0.0.1] port 8964.
debug1: Connection established.
debug1: identity file /Users/Lighter/.ssh/id_rsa type 0
debug1: identity file /Users/Lighter/.ssh/id_rsa-cert type -1
debug1: identity file /Users/Lighter/.ssh/id_dsa type -1
debug1: identity file /Users/Lighter/.ssh/id_dsa-cert type -1
debug1: identity file /Users/Lighter/.ssh/id_ecdsa type 2
debug1: identity file /Users/Lighter/.ssh/id_ecdsa-cert type -1
debug1: identity file /Users/Lighter/.ssh/id_ed25519 type -1
debug1: identity file /Users/Lighter/.ssh/id_ed25519-cert type -1
debug1: identity file /Users/Lighter/.ssh/id_xmss type -1
debug1: identity file /Users/Lighter/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.1
debug1: Remote protocol version 2.0, remote software version OpenSSH_8.2p1 Ubuntu-4ubuntu0.1
debug1: match: OpenSSH_8.2p1 Ubuntu-4ubuntu0.1 pat OpenSSH* compat 0x04000000
debug1: Authenticating to 127.0.0.1:8964 as 'Lighter'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256@libssh.org
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:efxiadogxOHYAx2SinQT6v2fqIpGQxuZeAP7LNx/l7g
debug1: Host '[127.0.0.1]:8964' is known and matches the ECDSA host key.
debug1: Found key in /Users/Lighter/.ssh/known_hosts:6
debug1: rekey out after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey in after 134217728 blocks
debug1: Will attempt key: /Users/Lighter/.ssh/id_rsa RSA SHA256:NuR1ClQtXikP9fVFaJ4X1duTxN5M3XpC6/ihuZrd8wA
debug1: Will attempt key: /Users/Lighter/.ssh/id_dsa
debug1: Will attempt key: /Users/Lighter/.ssh/id_ecdsa ECDSA SHA256:BEGqSHGs5ctncTbVzSnthaXr19Awt4XQKVpltCf//Ok
debug1: Will attempt key: /Users/Lighter/.ssh/id_ed25519
debug1: Will attempt key: /Users/Lighter/.ssh/id_xmss
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519,sk-ssh-ed25519@openssh.com,ssh-rsa,rsa-sha2-256,rsa-sha2-512,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,sk-ecdsa-sha2-nistp256@openssh.com>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Offering public key: /Users/Lighter/.ssh/id_rsa RSA SHA256:NuR1ClQtXikP9fVFaJ4X1duTxN5M3XpC6/ihuZrd8wA
debug1: Authentications that can continue: publickey,password
debug1: Trying private key: /Users/Lighter/.ssh/id_dsa
debug1: Offering public key: /Users/Lighter/.ssh/id_ecdsa ECDSA SHA256:BEGqSHGs5ctncTbVzSnthaXr19Awt4XQKVpltCf//Ok
debug1: Authentications that can continue: publickey,password
debug1: Trying private key: /Users/Lighter/.ssh/id_ed25519
debug1: Trying private key: /Users/Lighter/.ssh/id_xmss
debug1: Next authentication method: password
Lighter@127.0.0.1's password:
debug1: Authentications that can continue: publickey,password
Permission denied, please try again.
Lighter@127.0.0.1's password:
debug1: Authentications that can continue: publickey,password
Permission denied, please try again.
Lighter@127.0.0.1's password:
debug1: Authentications that can continue: publickey,password
debug1: No more authentication methods to try.
Lighter@127.0.0.1: Permission denied (publickey,password).
在此之前,我尝试使用生成密钥ssh-genkey
并且它有效,因此我可以在没有密码的情况下连接到端口 22。但是虽然我在这里输入了正确的密码,它只是一直显示权限被拒绝。我搜索了整个互联网,但没有正确的答案。
这是我的/etc/ssh/sshd_config
# $OpenBSD: sshd_config,v 1.103 2018/04/09 20:41:22 tj 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.
Port 22
Port 8964
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::
#HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_ecdsa_key
#HostKey /etc/ssh/ssh_host_ed25519_key
# Ciphers and keying
#RekeyLimit default none
# Logging
#SyslogFacility AUTH
#LogLevel INFO
# Authentication:
#LoginGraceTime 2m
PermitRootLogin yes
#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
#AuthorizedKeysCommand none
#AuthorizedKeysCommandUser nobody
# For this to work you will also need host keys in /etc/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
# Change to no to disable s/key passwords
#ChallengeResponseAuthentication yes
# Kerberos options
#KerberosAuthentication no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes
#KerberosGetAFSToken no
# GSSAPI options
#GSSAPIAuthentication no
#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 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
#AllowAgentForwarding yes
#AllowTcpForwarding yes
GatewayPorts yes
X11Forwarding yes
X11DisplayOffset 10
X11UseLocalhost yes
#PermitTTY yes
#PrintMotd yes
#PrintLastLog yes
#TCPKeepAlive yes
#PermitUserEnvironment no
#Compression delayed
#ClientAliveInterval 0
#ClientAliveCountMax 3
#UseDNS no
#PidFile /var/run/sshd.pid
#MaxStartups 10:30:100
PermitTunnel yes
#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
# PermitTTY no
# ForceCommand cvs server
# XAuthLocation added by XQuartz (http://xquartz.macosforge.org)
XAuthLocation /opt/X11/bin/xauth
解决方案
我想出了我的问题,虽然使用 ssh 连接到 localhost,但必须使用远程用户名登录到远程服务器。所以这个命令是正确的:
ssh remoteuser@127.0.0.1 -p 8964
推荐阅读
- javascript - How can i get this timer to start on click instead of on page load?
- javascript - 使用 Ajax.BeginForm 发送邮件在服务器上不起作用
- file - 文件不会在 MQL4 中打开
- python - PyChram 中的终端没有显示输出
- r - Use a function to loop through rows, prior row is the input for the next row
- c# - 匿名类型。此上下文仅支持原始类型或枚举类型
- json - Does JSON schema have any standards or conventions for associating an instance document with the schema to which it conforms?
- reactjs - 将自定义单选按钮组件放入 Material UI 中的 Radio Group 中
- ubuntu - 在 ubunto 10 LXDE 中,我可以将 LXtreminal 配置为打开 bash --login shell
- lua - 当我运行我制作的这段代码时,FCEUX 停止响应