システムにclientというユーザーのchroot環境をセットアップしました。 WINSCPを使用して、公開鍵認証を使用してマシンからサーバーに接続しています。すべてが正常に機能し、ログインでき、ホームディレクトリ(jailディレクトリ)が表示され、上に移動できません。
私が現在抱えている問題は、ローカルマシンからサーバーにファイルをコピーできないことです。そうすると、次のようになりますアクセスが拒否されました:リモートファイル/home/client/test.txtを作成できません
私のサーバーはRedHatサーバーであり、これは私のsshd構成です。
Match User client
ChrootDirectory %h
PubkeyAuthentication yes
AllowTCPForwarding no
X11Forwarding no
ForceCommand internal-sftp
私はこれをオンラインで探しましたが、クライアントのホームディレクトリにbin
およびlib
フォルダーのコピーを作成することに関するメモをいくつか見つけましたが、これらの解決策は役に立ちませんでした。
現時点で必要なのは、ユーザーがローカルマシンからchrootフォルダーの下のサーバーにファイルをコピーできるようにすることだけです。
これが私がしたことの簡単な説明です:
私は彼らのホームディレクトリ内に投獄したchrootされたユーザー(ユーザー名:clientd)を持っています。このchrootディレクトリは/home/client/
で、rootが所有しています。
ここで、このクライアントユーザーが/mnt/datadrive/Tomcat/webapps
の下にあるTomcatWebアプリケーションフォルダーにアクセスできるようにする必要があります。
私がしたことは:
/home/client
の下にTomcat_ROOT
というフォルダーを作成し、clientdev
に所有権を付与します。コマンドを実行すると、次のようになります。
$ mount --bind /mnt/datadrive/Tomcat/webapps /home/client/Tomcat_ROOT
クライアントでログインすると、/home/client
内のディレクトリリストからフォルダが消えます。私のrootユーザーはそれを見ることができますが、目的のユーザーは見ることができません。
ここにいくつかの許可リストがあります:
ls -l /home/client/Tomcat_ROOT
の出力:
drwxr-xr-x. 6 root root 4096 Apr 11 15:07 .
drwxrwxr-x. 12 root root 4096 Apr 11 15:07 ..
drwxr-xr-x. 3 root root 4096 Apr 9 22:10 webapp1
drwxr-xr-x. 4 root root 4096 Mar 18 18:43 webapp2
drwxr-xr-x. 3 root root 4096 Apr 9 22:11 webapp3
drwxrwxr-x. 10 root root 4096 Apr 11 15:20 ROOT
ls -l /home/client/
の出力:
drwx------. 4 clientdev clientdev 4096 Apr 10 21:36 .
drwxr-xr-x. 7 root root 4096 Apr 10 22:07 ..
-rw-------. 1 client client 664 Apr 10 21:43 .bash_history
-rw-r--r--. 1 client client 18 Apr 23 2012 .bash_logout
-rw-r--r--. 1 client client 176 Apr 23 2012 .bash_profile
-rw-r--r--. 1 client client 124 Apr 23 2012 .bashrc
drwx------. 2 client client 4096 Apr 10 19:20 .ssh
drwxr-xr-x. 2 client client 4096 Apr 10 21:34 Tomcat_ROOT
私は似たような設定をしていて、それが機能するので、設定は私には有効に見えます。一致ルールの上にこの行を追加することをお勧めします。これにより、ログでもう少し詳細なメッセージが有効になり、根本的な問題に焦点を絞ることができます。
Subsystem sftp internal-sftp -f AUTH -l INFO
変更後は必ずsshd
を再起動してください。あなたの問題は、ディレクトリまたはユーザーのフォルダのいずれかのアクセス許可に関係していると思います。 ChrootDirectory
を使用する場合、必ず守らなければならない非常に特殊な条件がいくつかあります。そうしないと、SSHDは連携しません。
ChrootDirectory
Specifies the pathname of a directory to chroot(2) to after
authentication. All components of the pathname must be root-owned
directories that are not writable by any other user or group.
After the chroot, sshd(8) changes the working directory to the
user's home directory.
The pathname may contain the following tokens that are expanded at
runtime once the connecting user has been authenticated: %% is
replaced by a literal '%', %h is replaced by the home directory of
the user being authenticated, and %u is replaced by the username of
that user.
The ChrootDirectory must contain the necessary files and directories
to support the user's session. For an interactive session this
requires at least a Shell, typically sh(1), and basic /dev nodes
such as null(4), zero(4), stdin(4), stdout(4), stderr(4), arandom(4)
and tty(4) devices. For file transfer sessions using “sftp”, no
additional configuration of the environment is necessary if the in-
process sftp server is used, though sessions which use logging do
require /dev/log inside the chroot directory (see sftp-server(8) for
details).
The default is not to chroot(2).
ディレクトリの権限を確認してください。
フォルダ構造が/ home/test/appのように
/ home/testよりも-'chmod700 'および' chown testusertest 'および/ home/test/appが必要-'chmod750'および 'chown testuser app -R'
してみてください
chmod 700 /home/client/
chown clientd /home/client/
cd /home/client/
chmod 750 * -R
chown clientd clientdev * -R
また、ディレクトリのアクセス許可の変更が機能しない場合もお知らせください。