• 第一步添加一个git 用户 adduser git
  • 第二步设置git密码 passwd git
  • 第三步禁用shell登录,出于安全考虑,创建的git用户不允许登录shell,可以通过修改/etc/passwd 文件完成,具体如下:
  1. 找到 git-shell位置 使用命令:which git-shell 比如我的位置如下
    1. [root@bobo lib]# which git-shell
    2. /usr/bin/git-shell
  2. 打开/etc/shells 使用命令: vim /etc/shells 在最后加上/usr/bin/git-shell
  3. 接着打开/etc/passwd 文件,找到git用户这一行
  1. git:x:1001:1001::/home/git:/bin/bash
  2. 改成
  3. git:x:1001:1001::/home/git:/usr/bin/git-shell

这样,git用户可以正常通过ssh使用git,但无法登录shell,因为我们为git用户指定的git-shell每次一登录就自动退出。