CentOS5.7 で rssh と chroot の設定をする。
CentOS 5.7 に rssh の設定をするログ。
目的
1.rssh のインストール
yum 等では配布していないので、rssh の最新版を確認する
http://sourceforge.net/projects/rssh/files/rssh/
以下、サーバーに root でログインしたところから。
今回は、rssh-2.3.3。
# cd /usr/local/src/ # wget http://jaist.dl.sourceforge.net/sourceforge/rssh/rssh-2.3.3-1.src.rpm # wget http://jaist.dl.sourceforge.net/sourceforge/rssh/rssh-2.3.3.tar.gz
ソースと rpm を両方ダウンロード。
( 後でソースが必要となるため。自分でconfigureとmakeをするならrpmはいらない )
# rpmbuild --rebuild rssh-2.3.3-1.src.rpm # rpm -ihv /usr/src/redhat/RPMS/i386/rssh-2.3.3-1.i386.rpm # which rssh /usr/bin/rssh
rpm のビルド
# vi /etc/shells (追記) /usr/bin/rssh # vi /etc/rssh.conf (以下のコメントを外す) allowscp allowsftp
2.ユーザーの追加
# adduser -s /usr/bin/rssh -d /home/scptest scptest # passwd scptest # cat /etc/passwd (略) scptest:x:501:501::/home/scptest:/usr/bin/rssh
3. chroot の設定
# tar zxvf rssh-2.3.3.tar.gz # cp rssh-2.3.3/mkchroot.sh ~ # cd # ./mkchroot.sh /home/scptest # cd /home/scptest/ # vi etc/passwd (対象のユーザー以外を削除)
ソース内に入っている mkchroot.sh を使い、 対象ディレクトリに chroot の設定をする。
[chrootdir] /etc/passwd 内の不要なユーザー情報を削除する
4.動作確認
別のマシンからアクセスのテスト
$ ssh scptest@192.168.0.100 scptest@192.168.0.100's password: This account is restricted by rssh. Allowed commands: scp sftp If you believe this is in error, please contact your system administrator. Connection to 192.168.0.100 closed. $ scp dummy.txt scptest@192.168.0.100:. scptest@192.168.0.100's password: dummy.txt $ sftp scptest@192.168.0.100:. Connecting to 192.168.0.100... scptest@192.168.0.100's password: Changing to: /home/scptest/. sftp>
SCP / SFTP のみでアクセスできる事を確認。