jailkitでアクセス制限付きのsftp/scp専用アカウントを作成する

外部へのデータ転送のために、CentOS上にアクセス制限つきのsftp/scpしかできないアカウントを作成する方法を記載する
なお、作業は、鍵の作成以外は全てrootで行なった

jailkitのインストール

以下のコマンドで、jailkitをインストールする
なお、0.5.3-1.el6.rf.x86_64の部分は、http://pkgs.repoforge.org/rpmforge-release/ のリストから、使用しているCentOSのバージョンに合わせて変更する

# wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm
# rpm -ivh rpmforge-release-0.5.2-2.el5.rf.i386.rpm 
# yum install jailkit

jail用の親ディレクトリの準備

以下のコマンドで、jailkit用の親ディレクトリを用意する

# mkdir /jail
# jk_init -v -j /jail/sftp sftp scp jk_lsh

ユーザーの作成

仮に作成するユーザーを「hogehoge」とした場合、以下に記載のようにuseradd,passwdでユーザーの作成とパスワードの設定を行なった後、jk_jailuserでそのユーザーをjailに閉じ込める

# useradd hogehoge
# passwd hogehoge

鍵の作成

ここで、先ほど作成したユーザーに切り替える
「hogehoge」ユーザーの状態で、以下のハイライト部分のコマンドを実行する

$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/hogehoge/.ssh/id_rsa):
Created directory '/home/hogehoge/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/hogehoge/.ssh/id_rsa.
Your public key has been saved in /home/hogehoge/.ssh/id_rsa.pub.
The key fingerprint is:
00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00 hogehoge@www00000uo.sakura.ne.jp
The key's randomart image is:
+--[ RSA 2048]----+
|                 |
|                 |
|                 |
|                 |
|                 |
|                 |
|                 |
|                 |
|                 |
+-----------------+
$ cd .ssh
$ ls
id_rsa  id_rsa.pub
$ cp id_rsa.pub authorized_keys

ユーザーをjailに移動する

以下のコマンドで、該当のユーザーをjailに移動する

# jk_jailuser -j /jail/sftp hogehoge
home directory /home/hogehoge is not within /jail/sftp/, move the directory contents?
[Y]/[n]y

ユーザに実行権限を与える

jk_lsh.iniファイルを修正して、ユーザーに実行権限を与える

# vi /jail/sftp/etc/jailkit/jk_lsh.ini
[DEFAULT]
paths= /usr/bin, /usr/lib/
executables= /usr/bin/scp, /usr/libexec/openssh/sftp-server

[hogehoge]
paths= /usr/bin, /usr/lib/
executables= /usr/bin/scp, /usr/libexec/openssh/sftp-server

参考にしたサイト
Memo/Linux/jailkit – DEX Lab
EC2上でjailkitを使って、chroot環境でSCPできる環境構築

↓↓↓ブログランキングに参加しています↓↓↓

にほんブログ村 IT技術ブログへ

↑↑↑応援よろしくお願いします↑↑↑

■ AD ■

コメントを残す

メールアドレスが公開されることはありません。