假设我想将Mercurial仓库存储在/var/repos/REPO_NAME
上的服务器上,但是我想用ssh://hg.example.org/REPO_NAME
而不是ssh://hg.example.org//var/repos/REPO_NAME
push/pull来存储此仓库。我可以这样做吗?
即我想从路径中省略/var/repos
,而不必将存储库放在服务器的根目录中。
答案 0 :(得分:0)
我找到了 a 解决方案。不确定这是否是最好的。
首先,更新int arr[]; //initialize it
int siz=sizeof(arr)/sizeof(arr[0]);
int index=0;
while(index<siz-1)
{
arr[index]=arr[index+1];
index++;
}
arr[index]=0; //0 default value at the end of the array
来为用户设置/etc/ssh/sshd_config
的位置,因为我们将要更改其homedir,否则sshd将无法找到它:
authorized_keys
然后将其homedir更改为您想要快速访问的位置:
Match User hg
AuthorizedKeysFile /home/hg/.ssh/authorized_keys
您可以验证它是否已在usermod -d /var/repos hg
中设置。
然后重新启动cat /etc/passwd
以使更改生效:
sshd
以hg用户身份登录SSH进行验证:
/etc/init.d/ssh restart
尝试克隆:
ssh hg@example.org
pwd # /var/repos
exit
PS:我知道这是用户,而不是子域。我仍在弄清楚>。<< / p>
答案 1 :(得分:0)
通过结合this answer和this article找到了另一个解决方案。
只需编辑authorized_keys
文件:
nano /home/hg/.ssh/authorized_keys
将cd
的命令添加到您选择的目录中:
command="cd /var/repos && $SSH_ORIGINAL_COMMAND" ssh-rsa AAAAB3...
这里的窍门是使用$SSH_ORIGINAL_COMMAND
。如果您在这些链接中使用$SHELL
或/bin/bash -l
,Mercurial将不喜欢它:
mark@MARK-DESKTOP /tmp % hg clone ssh://hg@example.org/repo
remote: /bin/bash: line 1: hello: command not found
remote: /bin/bash: line 2: between: command not found
remote: /bin/bash: line 3: pairs: command not found
但是使用上面的方法,它可以很好地工作,并且您不必更改homedir!
它实际上具有不再允许您使用SSH的副作用:
mark@MARK-DESKTOP /tmp % ssh hg@example.org
Connection to example.org closed.
我认为它只允许您执行一个命令,然后退出。但这就是Mercurial的运作方式,因此可以用于此目的。