vsftpd

vsftp のインストールは下記参照。

hirose-test.hatenablog.com

SFTPで接続してみる。

PS C:\Users\admin> sftp root@180.147.255.201
The authenticity of host '180.147.255.201 (180.147.255.201)' can't be established.
ECDSA key fingerprint is SHA256:E3aaaRNhDHU2tqzLUKnzm/avbuE+d2dmDQfZQHH4C5M.
Are you sure you want to continue connecting (yes/no)?

Warning: Permanently added '180.147.255.201' (ECDSA) to the list of known hosts.

root@180.147.255.201's password:
Connected to root@180.147.255.201.
sftp> pwd
Remote working directory: /root
sftp>

匿名 FTP 機能の停止

$ cd /etc/vsftpd/
$ ls
ftpusers  user_list  vsftpd.conf  vsftpd_conf_migrate.sh

$ sudo vim vsftpd.conf
# Allow anonymous FTP? (Beware - allowed by default if you comment this out).
anonymous_enable=YES → No に変更

$ sudo systemctl restart vsftpd

FTP 専用ユーザの作成

$ sudo useradd -s /sbin/nologin intern02_ftp -d /var/www/vhosts/intern02.db-force.net/
$ sudo passwd intern02_ftp
ユーザー intern02_ftp のパスワードを変更。
新しいパスワード:
新しいパスワードを再入力してください:
passwd: すべての認証トークンが正しく更新できました。

$ sudo useradd -s /sbin/nologin hirose_ftp -d /var/www/vhosts/hirose.com/
$ sudo passwd hirose_ftp
ユーザー hirose_ftp のパスワードを変更。
新しいパスワード:
新しいパスワードを再入力してください:
passwd: すべての認証トークンが正しく更新できました。

FTP 専用ユーザの設定確認

PS C:\Users\admin> ssh intern02_ftp@180.147.255.201 ← ftp専用ユーザーでSSH接続
intern02_ftp@180.147.255.201's password:
This account is currently not available. ← 現在利用できないと表示される
Connection to 180.147.255.201 closed.

PS C:\Users\admin> ssh hirose_ftp@180.147.255.201
hirose_ftp@180.147.255.201's password:
This account is currently not available.
Connection to 180.147.255.201 closed.

FTP接続の方は
PS C:\Users\admin> ftp 180.147.255.201
180.147.255.201 に接続しました。
220 (vsFTPd 3.0.2)
200 Always in UTF8 mode.
ユーザー (180.147.255.201:(none)): intern02_ftp
331 Please specify the password.
パスワード:
230 Login successful.
ftp> pwd
257 "/home/intern02_ftp"
ftp> quit
221 Goodbye.

PS C:\Users\admin> ftp 180.147.255.201
180.147.255.201 に接続しました。
220 (vsFTPd 3.0.2)
200 Always in UTF8 mode.
ユーザー (180.147.255.201:(none)): hirose_ftp
331 Please specify the password.
パスワード:
230 Login successful.
ftp> pwd
257 "/var/www/vhosts/hirose.com"
ftp> quit
221 Goodbye.

移動制限(利用できるディレクトリをログインディレク トリ 配下だけに限定する)

現在
ftp> pwd
257 "/var/www/vhosts/hirose.com"
ftp> cd ../
250 Directory successfully changed.
ftp> pwd
257 "/var/www/vhosts"
ftp>
$ sudo vi vsftpd.conf
# You may specify an explicit list of local users to chroot() to their home
# directory. If chroot_local_user is YES, then this list becomes a list of
# users to NOT chroot().
# (Warning! chroot'ing can be very dangerous. If using chroot, make sure that
# the user does not have write access to the top level directory within the
# chroot)
#chroot_local_user=YES
chroot_list_enable=YES ← コメントアウトを外す(移動制限を掛けるユーザリストを使う)
# (default follows)
chroot_list_file=/etc/vsftpd/chroot_list ← コメントアウトを外す(移動制限を掛けるユーザリスト)

alow _ writeable_ch root は、ユーザのホームディレクトリが哲き込み可能な状 態でもログインを許可します(この状態が一般的)

# sudo vim chroot_list
intern02_ftp
hirose_ftp
$ sudo systemctl restart vsftpd
$ sudo systemctl is-active vsftpd
active

ログインディレクトリから上に行けなくなった

230 Login successful.
ftp> pwd
257 "/"
ftp> cd ../
250 Directory successfully changed.
ftp> pw
257 "/"
/* -----codeの行番号----- */