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


14

我已将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上

Answers:


19

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

[tunnels]
foo = ssh -p 20000

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


另外,如果要覆盖默认svn+ssh协议的端口,只需定义即可ssh = ssh -p 20000。假设您已经/etc/ssh/sshd_config在服务器上进行了修改,以Port 22代替Port 20000
2013年

1
@Dogbert:不能像您说的那样工作:我尝试过ssh = ssh -p 20000然后尝试结帐,svn+ssh://example.org/var/svn-repos/mydev/trunk但这仍然尝试在端口22上进行
rubo77

13

每当需要通过非默认端口或使用其他用户名访问ssh服务器时,都可以在中定义别名~/.ssh/config

Host mysvn
HostName server.com
Port 20000
User jm

然后运行svn co svn+ssh://mysvn/home/svn/proj1


4

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

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

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


0

如果你的〜/的.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隧道,则此方法将不起作用,在这种情况下,配置文件优先。(这很不寻常。通常情况相反,环境变量通常优先于配置文件)

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.