AWS re:Postを使用することにより、以下に同意したことになります 利用規約

Lightsail インスタンスで FTP サーバーと FTP ユーザーを設定するにはどうすればよいですか。

所要時間2分
0

Amazon Linux 2、CentOS、Ubuntu、または Debian を実行している Lightsail インスタンスに FTP サーバーと FTP ユーザーを設定したいと考えています。これを行うにはどうすればよいですか?

解決方法

注: FTP では、すべてのデータとパスワードをプレーンテキストで送信します。SFTP は、インスタンスに接続してデータを送信する、より安全な方法です。SFTP の使用方法については、「SFTP を使用して Amazon Lightsail で Linux または Unix インスタンスに接続する」を参照してください。SFTP ユーザーの作成については、「Lightsail インスタンスで SFTP ユーザーを作成するにはどうすればよいですか。」を参照してください。

1.    次のコマンドを実行して、VSFTPD パッケージをインストールします。

Amazon Linux 2 と CentOS

sudo yum install vsftpd -y

Ubuntu と Debian

sudo apt install vsftpd -y

2.    vsftpd.config ファイルを編集して、環境に必要な変数を変更します。

vsftpd.config ファイルの場所は、オペレーティングシステムによって異なります。

  • Amazon Linux 2 と CentOS: /etc/vsftpd/vsftpd.conf
  • Debian と Ubuntu: /etc/vsftpd.conf

環境に応じて、次の例の変数を変更します。

anonymous_enable=NO
local_enable=YES
write_enable=YES
dirmessage_enable=YES
xferlog_enable=YES
connect_from_port_20=NO
xferlog_std_format=YES
chroot_local_user=YES
allow_writeable_chroot=YES
chroot_list_file=/etc/vsftpd/chroot_list
listen=YES
pam_service_name=vsftpd
userlist_enable=YES
userlist_file=/etc/vsftpd/user_list
userlist_deny=NO
listen_port=10021
pasv_enable=YES
pasv_min_port=21000
pasv_max_port=21999
pasv_addr_resolve=NO

注: ポート 21 は FTP のデフォルトポートです。ポート 21 を使用できます。ただし、前述の例では、セキュリティ上の理由から、カスタムポート 10021 が FTP のポートとなっています。ポートをカスタマイズするには、listen_port を使用したいポートに変更し、connect_from_port_20NO に設定します。インスタンスのファイアウォールで FTP のために使用する予定のポートを必ずアクティブ化してください。前の例では、ポート 10021 と 21000~21999 がカスタムファイアウォールと Lightsail ファイアウォールでアクティブ化されています。

3.    次のコマンドを実行して FTP ユーザーを追加します。

sudo adduser --home /home/ftp_user ftp_user

注: 前の例で、ftp_user を任意のユーザー名に置き換えます。

4.    次のコマンドを実行して、ユーザーのパスワードを作成します。

sudo passwd ftp_user

5.    次のコマンドを実行して、/home/ftp_user ファイルの所有権を変更します。このコマンドは、ftp_user をファイルの所有者にします。

sudo chown ftp_user:ftp_user -R /home/ftp_user/

6.    次のコマンドを実行して、新しいユーザーを vsftpd user_list に追加します。-a フラグを使用してファイルに追加します。

Amazon Linux 2 と CentOS

sudo echo "ftp_user" | sudo tee -a /etc/vsftpd/user_list

Debian と Ubuntu

次のコマンドを実行して userlist ファイルを作成し、新しいユーザーをファイルに追加します。

sudo echo "ftp_user" | sudo tee -a /etc/vsftpd.userlist

7.    vsftpd サービスを再起動します。

sudo systemctl restart vsftpd

8.    FTP サーバーに接続します。次の例では、Filezilla プレーン FTP を使用しています。

Status:    Connecting to 54.xxx.xxx.x2:10021...
Status:    Connection established, waiting for welcome message...
Status:    Plain FTP is insecure. Please switch to FTP over TLS.
Status:    Logged in
Status:    Retrieving directory listing...
Status:    Server sent passive reply with unroutable address. Using server address instead.
Status:    Calculating timezone offset of server...
Status:    Timezone offset of server is 0 seconds.
Status:    Directory listing of "/" successful
Status:    Connecting to 54.xxx.1xx.52:10021...
Status:    Connection established, waiting for welcome message...
Status:    Plain FTP is insecure. Please switch to FTP over TLS.
Status:    Logged in
Status:    Starting upload of C:\Users\Administrator\Documents\FTPtest.txt
Status:    Server sent passive reply with unroutable address. Using server address instead.
Status:    File transfer successful, transferred 10 bytes in 1 second
Status:    Retrieving directory listing of "/"...
Status:    Server sent passive reply with unroutable address. Using server address instead.
Status:    Directory listing of "/" successful

FTP サーバーのセットアップをトラブルシューティングする

vsftpd.conf ファイルのオプションが間違っていると、vsftpd サービスがダウンする場合があります。起動できない場合は、次のコマンドを実行して、正しく設定されていないオプションを見つけます。

Amazon Linux 2 と CentOS

sudo /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf

Debian と Ubuntu

sudo /usr/sbin/vsftpd /etc/vsftpd.conf

AWS公式
AWS公式更新しました 1年前