在外部端口/ IP(本地IP工作正常)ssh(和git)身份验证问题

问题描述:

我想在可通过Internet远程访问的服务器计算机上设置git存储库。在外部端口/ IP(本地IP工作正常)ssh(和git)身份验证问题

我已经成功地通过本地/内部IP地址获得git工作。在本地局域网内,我有基于私钥的身份验证,可用于SSH(禁用密码登录),并且可以使用Git和SSH成功​​克隆,推送和拉取,例如:

ssh [email protected] 
[-> accepts public key, gives me a remote console prompt as "USER", etc] 

git clone git+ssh://[email protected]//gitdir/project.git 
[-> creates a local clone as desired, commits and push work, no problems seemingly] 

不过,我现在想通过外部/互联网IP访问本机以同样的方式,我不知道它让我的行为。

  • 我已启用端口转发在我的路由器端口22到服务器机器。
  • 我在服务器上的“UFW”软件中打开了端口22。
  • 据我所知,我的路由器,SSH配置或UFW上没有任何设置,可以阻止任何特定的网址或以其他方式在本地计算机或服务器上导致问题。服务器应该接受来自通过端口22访问的任何外部地址的连接,并且我的本地机器和服务器通常允许传出连接。

  • 我在本地机器上使用Ubuntu 17.04,如果有问题的话。

  • 服务器和本地计算机都在同一LAN /连接到相同的路由器。

  • 我禁用了“ChallengeResponseAuthentication”和“PasswordAuthentication”,并在我的“sshd_config”中启用了“PubkeyAuthentication”。

  • 我有四次检查,我使用的是正确的IP,并使用复制粘贴,而不是手动输入。除非我真的错过了某些东西,否则我会尝试连接到正确的机器。

对于直接SSH登录,我得到这个(使用-v标志):

[email protected]:~$ ssh -v -i ~/.ssh/[PRIVATE_KEY] [email protected][IP6_EXTERNAL_IP] 
OpenSSH_7.4p1 Ubuntu-10, OpenSSL 1.0.2g 1 Mar 2016 
debug1: Reading configuration data /home/[HOME]/.ssh/config 
debug1: Reading configuration data /etc/ssh/ssh_config 
debug1: /etc/ssh/ssh_config line 19: Applying options for * 
debug1: Connecting to [IP6_EXTERNAL_IP] [[IP6_EXTERNAL_IP]] port 22. 
debug1: Connection established. 
debug1: identity file /home/[HOME]/.ssh/[PRIVATE_KEY] type 4 
debug1: key_load_public: No such file or directory 
debug1: identity file /home/[HOME]/.ssh/[PRIVATE_KEY]-cert type -1 
debug1: Enabling compatibility mode for protocol 2.0 
debug1: Local version string SSH-2.0-OpenSSH_7.4p1 Ubuntu-10 
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.4p1 Ubuntu-10 
debug1: match: OpenSSH_7.4p1 Ubuntu-10 pat OpenSSH* compat 0x04000000 
debug1: Authenticating to [IP6_EXTERNAL_IP] as 'USER' 
debug1: SSH2_MSG_KEXINIT sent 
debug1: SSH2_MSG_KEXINIT received 
debug1: kex: algorithm: curve25519-sha256 
debug1: kex: host key algorithm: ecdsa-sha2-nistp256 
debug1: kex: server->client cipher: [email protected] MAC: <implicit> compression: none 
debug1: kex: client->server cipher: [email protected] MAC: <implicit> compression: none 
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY 
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:[SHA_HASH] 
debug1: Host '[IP6_EXTERNAL_IP]' is known and matches the ECDSA host key. 
debug1: Found key in /home/[HOME]/.ssh/known_hosts:4 
debug1: rekey after 134217728 blocks 
debug1: SSH2_MSG_NEWKEYS sent 
debug1: expecting SSH2_MSG_NEWKEYS 
debug1: SSH2_MSG_NEWKEYS received 
debug1: rekey after 134217728 blocks 
debug1: SSH2_MSG_EXT_INFO received 
debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519,ssh-rsa,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521> 
debug1: SSH2_MSG_SERVICE_ACCEPT received 
debug1: Authentications that can continue: publickey,password 
debug1: Next authentication method: publickey 
debug1: Offering ED25519 public key: /home/[HOME]/.ssh/[PRIVATE_KEY] 
debug1: Authentications that can continue: publickey,password 
debug1: Next authentication method: password 
[email protected][IP6_EXTRNAL_IP]'s password: 

...,没有密码我公司供应的作品。我不知道为什么服务器甚至要求输入密码,我在“sshd_config”中全局禁用了密码登录,并且我已经三重检查了此用户也没有例外。

当我试图通过外部IP从服务器克隆(因为它通过SSH工作当然),Git同样要求我的远程用户密码,如果我按照以下步骤将它设置为使用外部IP,而不是原始本地IP:

git remote set-url origin ssh+git://[email protected][REMOTE_IP]//gitdir/project.git 

任何帮助了解我在这里失踪的东西将不胜感激;谢谢。

+0

sshd配置中PasswordAuthentication的值是什么? – wargre

+0

@wargre“PasswordAuthentication no”。正如我所说,它已被禁用。 –

+0

没有在/ var/log/secure? – wargre

想通了:

我不清楚为什么,但我的系统不喜欢它,当我尝试通过外部公网IP访问我的服务器,从我自己的内部局域网。我认为这是因为某些类型的包混淆,因为本地计算机和服务器计算机通过路由器共享相同的公共IP(有关此方面的确认,我们将不胜感激)。

当我试图从另一个网络连接,事情正常工作,并按预期。如果我没有提供正确的密码,我被要求输入公共密钥并立即拒绝,并且没有密码提示,并且在将我的repo源更改为使用公共ip后,SSH和SSH通过SSH似乎按照需要工作。通过编辑〜/ .ssh/config来设置密钥身份和主机的任何进一步细节。

标记为已解决。谢谢。