如何在非标准端口上使用 SSH 配置 SVN/SSH?

如何在非标准端口上使用 SSH 配置 SVN/SSH?

我已将 SSH 配置为端口 20000。当我尝试时:

svn co svn+ssh://server.com:20000/home/svn/proj1 proj1 --username jm

我明白了

svn: To better debug SSH connection problems, remove the -q option
from 'ssh' in the [tunnels] section of your Subversion configuration
file. svn: Network connection closed unexpectedly

我想我还需要告诉 SVN 使用端口 20000 吗?

我使用的是 Ubuntu 11.10

答案1

您可以在 Subversion 配置中定义新的“隧道”( ~/.subversion/config)。找到该部分[tunnels]并定义如下内容:

[tunnels]
foo = ssh -p 20000

之后您可以通过 URL 联系您的存储库svn+foo://server.com/home/svn/proj1 proj1

答案2

每当您需要在非默认端口或使用不同的用户名访问 ssh 服务器时,您可以在中定义别名~/.ssh/config

Host mysvn
HostName server.com
Port 20000
User jm

然后跑svn co svn+ssh://mysvn/home/svn/proj1

答案3

如果由于某种原因您无法编辑该~/.subversion/config文件,则可以在命令行中指定端口:

svn co svn+ssh://joe@myserver/myrepo/ --config-option="config:tunnels:ssh=ssh -p 20000"

但每次运行该svn命令时都必须执行此选项。这对于构建代理来说可能有意义。

答案4

如果你的 ~/.subversion/config 文件才不是定义了 ssh 隧道,您可以使用 SVN_SSH 环境变量在每次调用时覆盖 ssh 命令

SVN_SSH='ssh -p 20000' svn co svn+ssh://server.com/home/svn/proj1 proj1 --username jm

例如

deo@fox:~$ SVN_SSH='ssh -v -p 20000' svn ls svn+ssh://svn/
OpenSSH_7.9p1 Debian-10, OpenSSL 1.1.1c  28 May 2019
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to svn [192.168.177.2] port 20000.
debug1: connect to address 192.168.177.2 port 20000: Connection refused
ssh: connect to host svn port 20000: Connection refused
svn: E170013: Unable to connect to a repository at URL 'svn+ssh://svn'
svn: E210002: To better debug SSH connection problems, remove the -q option from 'ssh' in the [tunnels] section of your Subversion configuration file.
svn: E210002: Network connection closed unexpectedly

如果你的 ~/.subversion/config 文件,这将不起作用定义 ssh 隧道,在这种情况下配置文件优先。 (这是相当不寻常的。通常情况相反,环境变量通常优先于配置文件)

相关内容