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

本文已迁移至我的个人技术博客:

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

请移步至上述链接查看最新版本,谢谢各位支持!


[旧版文章内容]

在前面的文章中,为大家介绍了如何自己架设一个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连接来进行pushpull,而不能用来登陆服务器了。

$ 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.
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值