8
13

More than 5 years have passed since last update.

FTP Server on CentOS7 を構築する

Posted at

KVM ゲスト OS インストール用の iso ファイル等を Windows 環境からアップロードするために FTP Server を構築する

vsftpd をインストール

# yum install vsftpd

設定ファイル編集

# vi /etc/vsftpd/vsftpd.conf
anonymous_enable=NO #匿名アクセス無効
chroot_local_user=YES #ホームディレクトリより上位へのアクセス禁止
chroot_list_enable=YES #ホームディレクトリより上位へのアクセス許可リストを有効化
chroot_list_file=/etc/vsftpd/chroot_list #アクセス許可リスト
listen=YES #IPv4でリッスンする
listen_ipv6=NO #IPv6はリッスンしない
userlist_enable=YES
userlist_deny=NO
userlist_file=/etc/vsftpd/user_list
rsa_cert_file=/etc/pki/tls/certs/vsftpd.pem #サーバ証明書

ユーザリストに ftp 接続用ユーザを追加

# vi /etc/vsftpd/user_list
testuser

chroot_list ユーザのリスト作成

# vi /etc/vsftpd/chroot_list
testuser

サーバ証明書作成

# cd /etc/pki/tls/certs/
# make vsftpd.pem
umask 77 ; \
PEM1=`/bin/mktemp /tmp/openssl.XXXXXX` ; \
PEM2=`/bin/mktemp /tmp/openssl.XXXXXX` ; \
/usr/bin/openssl req -utf8 -newkey rsa:2048 -keyout $PEM1 -nodes -x509 -days 365 -out $PEM2 -set_serial 0 ; \
cat $PEM1 >  vsftpd.pem ; \
echo ""    >> vsftpd.pem ; \
cat $PEM2 >> vsftpd.pem ; \
rm -f $PEM1 $PEM2
Generating a 2048 bit RSA private key
...............+++
......................+++
writing new private key to '/tmp/openssl.XjyYCB'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:JP
State or Province Name (full name) []:Tokyo
Locality Name (eg, city) [Default City]:Sinagawa
Organization Name (eg, company) [Default Company Ltd]:xxx.com
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server's hostname) []:ftp.xxx.com
Email Address []:root@xxx.com

vsftpd 起動

# systemctl start vsftpd

vsftpd の自動起動設定

# systemctl enable vsftpd
Created symlink from /etc/systemd/system/multi-user.target.wants/vsftpd.service to /usr/lib/systemd/system/vsftpd.service.

ファイアウォールの設定

# firewall-cmd --add-service=ftp
success
# firewall-cmd --add-service=ftp --permanent
success
# firewall-cmd --list-services
dhcpv6-client ftp ssh

root で ftp 接続したい場合は、ftpusers の root をコメントアウトする

# vi /etc/vsftpd/ftpusers
#root

root での ftp 接続はセキュリティの観点から許可されておらず、/etc/pam.d/vsftpd の 3 行目で拒否設定されている

# vi /etc/pam.d/vsftpd
#%PAM-1.0
session    optional     pam_keyinit.so    force revoke
auth       required     pam_listfile.so item=user sense=deny file=/etc/vsftpd/ftpusers onerr=succeed
auth       required     pam_shells.so
auth       include      password-auth
account    include      password-auth
session    required     pam_loginuid.so
session    include      password-auth
8
13
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
13