0

我在从局域网外部 ssh'ing 家庭服务器时遇到问题。

据我所知,当我在路由器上安装 VPN 客户端时,问题可能已经出现。但以前可能是这样的。我不确定。

我将其设置为通过密钥对进行验证,这样我就不必总是输入密码,但也允许密码访问,以便我的伙伴可以访问服务器。

通过 LAN 登录(用户名混淆)

$ ssh -v user@192.168.1.1
OpenSSH_5.9p1, OpenSSL 0.9.8x 10 May 2012
debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for *
debug1: Connecting to 192.168.1.1 [192.168.1.1] port 22.
debug1: Connection established.
debug1: identity file /Users/user/.ssh/id_rsa type 1
debug1: identity file /Users/user/.ssh/id_rsa-cert type -1
debug1: identity file /Users/user/.ssh/id_dsa type -1
debug1: identity file /Users/user/.ssh/id_dsa-cert type -1
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*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.9
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: DSA 3e:6e:35:b3:05:14:39:bb:6f:a6:29:4e:a3:a8:59:81
debug1: Host '192.168.1.1' is known and matches the DSA host key.
debug1: Found key in /Users/user/.ssh/known_hosts:1
debug1: ssh_dss_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/user/.ssh/id_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 279
debug1: read PEM private key done: type RSA
debug1: Authentication succeeded (publickey).
Authenticated to 192.168.1.1 ([192.168.1.1]:22).
debug1: channel 0: new [client-session]
debug1: Requesting no-more-sessions@openssh.com
debug1: Entering interactive session.
debug1: Sending environment.
debug1: Sending env LANG = en_AU.UTF-8
Welcome to Ubuntu 12.04.2 LTS (GNU/Linux 3.2.0-49-generic x86_64)user

通过域名登录(域名、用户名和ip地址被混淆,但正确)。注意 -p 标志的使用...必须这样做,因为所有流量都是通过路由器上的 VPN 发送的。VPN 服务允许指定端口的端口转发:

$ssh -v -p nnnnn user@my.domain.com
OpenSSH_6.2p2, OpenSSL 0.9.8k 25 Mar 2009
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to my.domain.com [xxx.xxx.xxx.xxx] port nnnnn.
debug1: Connection established.
debug1: identity file /usr/home/user/.ssh/id_rsa type 1
debug1: identity file /usr/home/user/.ssh/id_rsa-cert type -1
debug1: identity file /usr/home/user/.ssh/id_dsa type -1
debug1: identity file /usr/home/user/.ssh/id_dsa-cert type -1
debug1: identity file /usr/home/user/.ssh/id_ecdsa type -1
debug1: identity file /usr/home/user/.ssh/id_ecdsa-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 dropbear_2013.58
debug1: no match: dropbear_2013.58
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: sending SSH2_MSG_KEXDH_INIT
debug1: expecting SSH2_MSG_KEXDH_REPLY
debug1: Server host key: RSA 46:4c:2f:53:72:75:da:d8:e4:fc:d4:55:86:90:6a:3c
debug1: checking without port identifier
The authenticity of host '[my.domain.com]:nnnnn ([xxx.xxx.xxx.xxx]:nnnnn)' can't be established.
RSA key fingerprint is 46:4c:2f:53:72:75:da:d8:e4:fc:d4:55:86:90:6a:3c.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '[my.domain.com]:nnnnn,[xxx.xxx.xxx.xxx]:nnnnn' (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: 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: /usr/home/user/.ssh/id_rsa
debug1: Authentications that can continue: publickey,password
debug1: Trying private key: /usr/home/user/.ssh/id_dsa
debug1: Trying private key: /usr/home/user/.ssh/id_ecdsa
debug1: Next authentication method: password
user@my.domain.com's password:
debug1: Authentications that can continue: publickey,password
Permission denied, please try again.
user@my.domain.com's password:

这是我的 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
#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
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
Subsystem sftp internal-sftp

# 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

有谁知道这里发生了什么?

我可以通过端口 80 连接到域(开发网站显示正常),但显然不能从局域网外部使用 git 或 sftp,因为它们使用端口 22。

谢谢。

4

1 回答 1

0

我解决了 - 路由器上的 VPN 正在破坏它。当然它仍然在局域网上工作,因为 nat 会为我解决这个问题。

当我从不同的位置测试 ssh 时,我得到了:

ssh -v user@my.domain.name
OpenSSH_6.2p2, OpenSSL 0.9.8k 25 Mar 2009
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to my.domain.name [xx.xx.xx.xx] port 22.
debug1: connect to address xx.xx.xx.xx port 22: Connection timed out
ssh: connect to host my.domain.name port 22: Connection timed out

所以它无法解析域名,也无法解析端口。

我必须做的:

  1. 访问 AirVPN 站点,设置一个随机端口转发,并将其出口端口设置为 22。
  2. 不要在路由器上进行端口转发。
  3. 为 NAT 设置 iptables 以将端口 22 路由到计算机:

    iptables -I FORWARD -i tun11 -p udp -d xx.xx.xx.xx --dport 22 -j ACCEPT

    iptables -I FORWARD -i tun11 -p tcp -d xx.xx.xx.xx --dport 22 -j ACCEPT

    iptables -t nat -I PREROUTING -i tun11 -p tcp --dport 22 -j DNAT --to-destination xx.xx.xx.xx

    iptables -t nat -I PREROUTING -i tun11 -p udp --dport 22 -j DNAT --to-destination xx.xx.xx.xx

于 2013-07-27T23:48:33.200 回答