轻作



重拾写作的乐趣

SVN使用SSH

2020.03.07

SSH配置方面和通常用Git一样,密码或者Key。
SVN使用SSH时,SVN用户名用的就是SSH登录的用户名,所以配置就很简单明了。

仓库认证配置 conf/authz

[/]
...
# 本机用户名 = 权限
username = rw
...

仓库密码配置 conf/passwd

[users]
...
# 为了方便使用,无密码
# 本机用户名 = 
username = 
...

SSH端口不是22的时候

配置 ~/.subversion/config

[tunnels]
...
ssh = ssh -p 22222
...

然后

# 使用绝对SVN目录路径
svn checkout svn+ssh://USERNAME@SSH_HOST/path/to/the-svn-repo

要想禁止SSH Key登录shell, 需要在.ssh/authorized_keys上设置

# --tunnel-user 不设置默认就是SSH用户名
command="svnserve --root=<ReposRootPath> --tunnel --tunnel-user=<RepoAuthUsername>",no-port-forwarding,no-agent-forwarding,no-X11-forwarding,no-pty ssh-rsa <YourPublicKey> <Comment>

然后

# 使用相对SVN根目录路径
svn checkout svn+ssh://USERNAME@SSH_HOST/the-svn-repo

想要像git-shelll一样, 可使用svn-shell, 这样就可以在正常服务的同时禁止SSH Key登录并显示友好信息

Widdows客户端使用参考

Securing Svnserve using SSH

用户以及用户组等和平常运维时一样

Match User git
    X11Forwarding no
    AllowTcpForwarding no
    PermitTTY no
    AuthenticationMethods publickey
    ForceCommand /bin/bash -c "if [[ -n \"$SSH_ORIGINAL_COMMAND\" ]];then /bin/git-shell -c \"$SSH_ORIGINAL_COMMAND\"; else /bin/git-shell; fi"

Match User svn
    X11Forwarding no
    AllowTcpForwarding no
    PermitTTY no
    AuthenticationMethods publickey
    ForceCommand /bin/bash -c "if [[ -n \"$SSH_ORIGINAL_COMMAND\" ]];then /bin/svn-shell -c \"$SSH_ORIGINAL_COMMAND\"; else /bin/svn-shell; fi"
发表评论