为 mercurial pulls/clone 创建一个 ssh-key

goa*_*ens 4 ssh mercurial

我想制作一个可以分发给远程用户的 ssh 密钥(无密码),以便他们可以对我的存储库进行 hg pull 或 hg 克隆。我已经制作了一个仅使用命令 /usr/bin/hg 的 ssh 密钥,但是在使用 clone 或 pull 命令时不起作用,因为命令字符串与远程命令调用 mercurial 的任何内容都不匹配内部使用。

当您执行以下操作时,是否可以在远程主机上获取 mercurial 执行的命令:

hg clone ssh://user@host//path-to-repo
hg pull ssh://user@host//path-to-repo
Run Code Online (Sandbox Code Playgroud)

我能否可靠地提出几个涵盖我所有基础的命令字符串?如果他们要拉取特定的修订版,是否会通过 ssh 使用不同的远程命令?

Ry4*_*ase 6

Mercurial 带有已经为这种受限访问设置的方便脚本。该脚本可能已经在您的服务器上并被命名为 hg-ssh,但您也可以在这里找到它:http : //www.selenic.com/repo/hg-stable/raw-file/tip/contrib/hg-ssh

要使用它,只需在您的/home/user/.ssh/authorized_keys文件中放置这样一行:

command="hg-ssh path/to/repo1 /path/to/repo2 ~/repo3 ~user/repo4" ssh-dss ...
Run Code Online (Sandbox Code Playgroud)

这将确保拥有该密钥的人只能使用 mercurial(而不是 shell)并且只能在您列出的存储库上使用。