大网数据广告活动
服务器运维问答

Limiting shell access for git users, but still allowing push / pull access

· 52CE 我爱测

I'm host a git repository on my server. Anyone can push / pull from the following remote url: ssh://[email omitted]/opt/git/my-project.git Specifically, anyone with ssh access to the [email omitted] user can push/pull (i.e. I hav…

问题原文

原帖链接 · user2490003 · CC BY-SA 4.0

I'm host a git repository on my server. Anyone can push / pull from the following remote url:

ssh://[email omitted]/opt/git/my-project.git

Specifically, anyone with ssh access to the [email omitted] user can push/pull (i.e. I have their public key listed as an authorized_key)

I'd like continue allowing push/pull access but I'd like to disable shell/login access

Github uses this approach - if you try to ssh into any of their git servers you get:

$ ssh [email omitted]
PTY allocation request failed on channel 0
Hi [USER]! You've successfully authenticated, but GitHub does not provide shell access.
Connection to github.com closed.

Specifically, I'd like to -

  1. Disable shell access via ssh and password for the git user
  2. Still allow myself (as root) to be able to assume the git user interactively
  3. Still allow developers to push / pull on the repository

I tried disabling the shell for the git user as follows:

root@example:~# usermod -s /usr/sbin/nologin git

This works great for #1 (ssh access is blocked) and #2 (I can still access the shell with sudo -u git -s /bin/bash)

However, #3 is not do-able. Cutting off shell access apparently also disables push/pull access (since it probably uses ssh).

Is there another solution here? How does Github themselves do this?

Thanks!

已采纳解答

原帖链接 · Syberspace · CC BY-SA 4.0

The easiest solution would be to use git-shell as the user's login-shell.

A detailed description on how to set this up can be found here: https://git-scm.com/docs/git-shell or alternatively on the git shell manpage man git shell

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2019-10-03)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。