Debian -- 特定のユーザーのコンソールアクセスを無効にする

Debian -- 特定のユーザーのコンソールアクセスを無効にする

gitサーバーが稼働しているサーバーがあります。

GitユーザーはLinuxユーザー名とパスワードを使用して複製、プッシュ、およびプールを実行できますが、Linuxコンソールにログインできないことを願っています。

Linuxコンソールを使用してアカウントをロックすると、passwd -lそのユーザーはLinuxコンソールにログインできなくなりますgit

/bin/falseデフォルトのシェルをgitに変更すると、Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.その資格情報を使用してサーバーにログインしようとするとパテがクラッシュします。

どんなアイデアがありますか?ありがとうございます。

ベストアンサー1

git-shellこれにはコマンドがあります。バラよりman git-shellもっと学ぶ。

設定方法は次のとおりです。

chsh -s /usr/bin/git-shell username

git cloneを仮定するとうまく機能~username/testrepo/.git/します。

git clone username@host:testrepo
Cloning into 'testrepo'...
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (3/3), done.
Checking connectivity... done.

上からssh username@host見るとわかります。

fatal: Interactive git shell is not enabled.
hint: ~/git-shell-commands should exist and have read and execute access.

接続が終了します。

スクリプトを含むディレクトリを作成することは可能ですが、スクリプトが常に実行され、出力を生成し、gitリポジトリの操作を中断するため、動作させることは~username/git-shell-commands/できません。git cloneしたがって、このディレクトリを作成しないことをお勧めします。


GitLabの機能に基づいた別のアプローチがあります。 1人のgitユーザーにすべてのリポジトリを所有させます。これにはすべてのホストキーが含まれます~git/.ssh/authorized_keys。各行には、次のようにオプションが接頭辞で付けられます。

command="~/bin/gitshell.sh",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty ssh-rsa AAAAB34234234.....

ここでは使用できないため、gitlab-shellカスタムスクリプトを使用します~git/bin/gitshell.sh

#!/bin/sh
exec git-shell -c "$SSH_ORIGINAL_COMMAND"

chshinコマンドが優先されるので、この方法は必要ありませんauthorized_keys

おすすめ記事