LoginSignup
16

More than 5 years have passed since last update.

EC2とS3を使用してsftpサーバを構築する

Last updated at Posted at 2015-10-17

EC2とS3を使用してsftpサーバを構築したのでメモ。

ソフトウェアアップデート


$ sudo yum update -y

サーバセキュリティ設定


$ vi /etc/ssh/sshd_config
AuthorizedKeysFile      .ssh/authorized_keys
PasswordAuthentication no
PermitRootLogin no
PubkeyAuthentication yes
〜編集終了

$ sudo service sshd restart

タイムゾーンの変更


$ sudo ln -sf /usr/share/zoneinfo/Asia/Tokyo /etc/localtime
$ sudo vi /etc/sysconfig/clock # ZONE="Asia/Tokyo"
$ sudo reboot
$ date # 時間確認

ユーザ編集


$ useradd auser
$ passwd auser
$ sudo su - auser
$ mkdir .ssh
$ cd .ssh
$ ssh-keygen -t rsa
$ mv id_rsa.pub authorized_keys
$ chmod 600 authorized_keys
$ cd ../
$ chmod 700 .ssh
$ cat .ssh/id_rsa # ローカルに保存

S3マウント

** S3マウントするために必要なパッケージをインストールする


$ sudo yum -y install automake 
$ sudo yum -y install gcc-c++ 
$ sudo yum -y install fuse 
$ sudo yum -y install fuse-devel 
$ sudo yum -y install libcurl-devel 
$ sudo yum -y install libxml2-devel 
$ sudo yum -y install openssl-devel

** s3fsのソースを取得する

$ wget https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/s3fs/s3fs-1.74.tar.gz
$ tar -xzf s3fs-1.74.tar.gz

** s3fsのインストール

$ cd s3fs-fuse-1.77
$ ./configure --prefix=/usr/local
$ make
$ sudo make install

** マウントポイント作成

$ sudo su -
$ echo 'XXXXXXXXXX:XXXXXXXXXX' > /etc/passwd-s3fs
$ mkdir -p /mnt/s3/
$ chmod 777 /mnt/s3/
$ s3fs s3 /mnt/s3/ -o rw,allow_other
$ df -h /mnt/s3/ # サイズが大きいはず
$ chmod -R 755 /mnt/s3/

ファイル参照設定

** auser, buserユーザの所定位置にシンボリックリンクを張る


$ ln -s /mnt/s3/auser/ s3
$ ln -s /mnt/s3/buser/ s3

sftp接続確認 (auserユーザで確認)

ユーザの秘密鍵を事前に配布、バケットにtest.txtを作成しておく。


$ chmod 600 id_rsa
$ sftp -oIdentityFile=./id_rsa auser@XXX.XXX.XXX.XXX
$ # パスフレーズ入力
sftp> get s3/test.txt
sftp> exit
$ ls -la # test.txtが存在すればOK

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
16