您的位置:首页 > 其它

Git Server - 限制 Git 用户使用SSH登陆操作

2017-06-09 10:12 405 查看
在前面的文章中,为大家介绍了如何自己架设一个
git
服务器并建立一个名为
git
的用户来进行所有的
git
操作。

那么如果我们想限制
git
用户,禁止其进行
SSH
登陆进行操作,我们可以将
git
用户的
shell
换成
git-shell
这个工具:

$ cat /etc/shells   # see if `git-shell` is already in there.  If not...
$ which git-shell   # make sure git-shell is installed on your system.
$ sudo vim /etc/shells  # and add the path to git-shell from last command


我们看到,首先需要找到
git-shell
的安装位置,如果没有被添加在/etc/shells中,我们需要手动将其添加进去(通常
git-shell
/usr/bin/git-shell
中)。

接下来,我们就可以把默认的
shell
替换成
git-shell
了:

$ sudo chsh git -s $(which git-shell)


现在,
git
用户只能使用
SSH
连接来进行
push
pull
,而不能用来登陆服务器了。

$ ssh git@gitserver
fatal: Interactive git shell is not enabled.
hint: ~/git-shell-commands should exist and have read and execute access.
Connection to gitserver closed.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: