首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >外部端口/ ip (本地ip工作正常)上的ssh (和git)身份验证问题

外部端口/ ip (本地ip工作正常)上的ssh (和git)身份验证问题
EN

Stack Overflow用户
提问于 2017-08-09 09:57:17
回答 1查看 315关注 0票数 0

我正试图在一台服务器机器上建立一个git存储库,该服务器可以通过互联网远程访问。

我已经成功地让git在本地/内部IP地址上工作。在本地局域网中,我有基于私钥的身份验证工作,为SSH (密码登录禁用),我可以克隆,推送,成功地使用Git和SSH,例如;

代码语言:javascript
复制
ssh USER@192.168.1.xxx
[-> accepts public key, gives me a remote console prompt as "USER", etc]

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

然而,我现在正试图以同样的方式通过外部/internet IP访问这台机器,我不明白它给了我什么行为。

  • 我已经为端口22启用了路由器上的端口转发到服务器机器。
  • 我在服务器上打开了"UFW“上的软件端口22。
  • 据我所知,我的路由器上没有设置,SSH吐露,或UFW会阻塞任何特定的web地址,或者在我的本地机器或服务器上造成问题。服务器应该接受来自通过端口22访问的任何外部地址的连接,并且我的本地机器和服务器通常都允许传出连接。
  • 我正在本地机器上使用Ubuntu17.04,如果这很重要的话。
  • 服务器和本地机器目前都在同一个LAN上/连接到同一个路由器。
  • 我禁用了"ChallengeResponseAuthentication“和"PasswordAuthentication",并在"sshd_config”中启用了"PubkeyAuthentication“。
  • 我已经四次检查我是否使用了正确的IP,并且使用复制粘贴而不是手动输入。除非我真的遗漏了什么,否则我正试图连接到正确的机器上。

对于直接的SSH登录,我得到以下内容(使用-v标志):

代码语言:javascript
复制
LOCALUSER@LOCALMACHINE:~$ ssh -v -i ~/.ssh/[PRIVATE_KEY] USER@[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: 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:[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
USER@[IP6_EXTRNAL_IP]'s password: 

...and没有我提供的密码有效。我不知道服务器为什么要问密码,我在"sshd_config“中全局禁用密码登录,并且我已经三次检查这个用户是否也不例外。

当我试图通过外部IP (当然是通过SSH )从服务器克隆时,Git同样要求我的远程用户的密码,如果我执行以下操作来设置它以使用外部IP,而不是原始的本地IP:

代码语言:javascript
复制
git remote set-url origin ssh+git://USER@[REMOTE_IP]//gitdir/project.git

如果你能帮助我理解我在这里所缺少的东西,我将不胜感激。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-08-09 22:25:09

弄明白了:

我不知道为什么,但我的系统不喜欢它,当我试图通过外部公共ip访问我的服务器,从我自己的局域网。我认为这是因为某种数据包混淆,因为本地机器和服务器机器通过路由器共享相同的公共ip (请确认这一点)。

当我试图从另一个网络连接时,事情就像预期的一样正常工作。我被要求要我的公钥,如果我没有提供正确的密码提示,立即拒绝,并且SSH和git通过SSH似乎在我改变我的回购源使用公共ip后在互联网上工作。编辑~/..ssh/config以设置关键标识和主机将涵盖任何进一步的细节。

标记问题解决了。谢谢。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45587384

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档