2018年3月12日月曜日

SFTP専用ユーザーの作成

sftpで特定のディレクトリだけアクセス許可するユーザーの作成手順。 sshd_configに以下の行を追加。
Match User sftp_user
 PasswordAuthentication yes # パスワード認証を許可
 ChrootDirectory /home/sftp_user # sftp_userディレクトリをホームディレクトリにする
 ForceCommand internal-sftp # sftpコマンドに制限
さらにSFTPの接続を処理するサブシステムを、標準のsftp-serverからsshd内部のinternal-sftpに変更。
#Subsystem      sftp    /usr/local/libexec/sftp-server
Subsystem       sftp    internal-sftp
sshdを再起動。 ホームディレクトリはroot所有でrootのみread/writeのパーミッションが必要なため変更。
# chown root:root /home/sftp_user
# chmod 755 /home/sftp_user