VPSサーバ立て直してやった事 (ユーザー追加, SSH公開鍵認証, VPN)
ブログをはてブロに移し終わったので、これまでブログおいていたさくらのVPSをリセットしました。
サーバの構築手順はググれば沢山出てくるし、いたってふつーの事しかやっていませんが、この後Ansible使って初期構築を自動化を企んでいるってのもあるので、それ用に作業内容を残しておきます。
※さくらのVPSで動かすことを前提としています
※systemctlコマンドも省いています、必要に応じてenable/disableするって感じで
OSアップデート
※標準OSインストールでCentOS入れたらupdate済みのようですが、念のため。。。
# yum update
ユーザー追加
# useradd -G wheel ユーザー名 # passwd ユーザー名 Changing password for user ******. New password: #パスワード入力 Retype new password: #もう1度パスワード入力 passwd: all authentication tokens updated successfully.
SSH公開鍵認証
変更前: #PermitRootLogin yes 変更後: PermitRootLogin no 変更前: PasswordAuthentication yes 変更後: PasswordAuthentication no
その後、公開鍵を作成してアップロード(id_rsa.pub)してコマンド実行
# mkdir /home/ユーザー名/.ssh # chown ユーザー名:グループ名 /home/ユーザー名/.ssh # chmod 700 /home/ユーザー名/.ssh # mv /アップロード先/id_rsa.pub /home/ユーザー名/.ssh/authorized_keys # chown ユーザー名:グループ名 /home/ユーザー名/.ssh/authorized_keys # chmod 600 /home/ユーザー名/.ssh/authorized_keys
VPNサーバ(SoftEther)設定
DLしてインストール
# cd /tmp/ # wget http://jp.softether-download.com/files/softether/v4.22-9634-beta-2016.11.27-tree/Linux/SoftEther_VPN_Server/64bit_-_Intel_x64_or_AMD64/softether-vpnserver-v4.22-9634-beta-2016.11.27-linux-x64-64bit.tar.gz # tar xvzf softether-vpnserver-v4.22-9634-beta-2016.11.27-linux-x64-64bit.tar.gz # cd vpnserver/ # make -------------------------------------------------------------------- SoftEther VPN Server (Ver 4.22, Build 9634, Intel x64 / AMD64) for Linux Install Utility Copyright (c) SoftEther Project at University of Tsukuba, Japan. All Rights Reserved. -------------------------------------------------------------------- Do you want to read the License Agreement for this software ? 1. Yes 2. No Please choose one of above number: # 1を入力 (中略) Did you read and understand the License Agreement ? (If you couldn't read above text, Please read 'ReadMeFirst_License.txt' file with any text editor.) 1. Yes 2. No Please choose one of above number: # 1を入力 Did you agree the License Agreement ? 1. Agree 2. Do Not Agree Please choose one of above number: # 1を入力 (中略) -------------------------------------------------------------------- make[1]: Leaving directory `/tmp/vpnserver' # cd ../ # mv vpnserver /usr/local
設定ファイルの作成
- /usr/local/vpnserver/setup_vpnserver.sh ※新規作成
#!/bin/sh sleep 3 tap_count=`nmcli d | grep tap_vpn | wc -l` if [ $tap_count -eq 1 ] then result=`ip addr add IPアドレス/サブネットマスク dev tap_vpn` exit $result fi
- /usr/lib/systemd/system/vpnserver.service ※新規作成
[Unit] Description=SoftEther VPN Server After=network.target local-fs.target [Service] Type=forking ExecStart=/usr/local/vpnserver/vpnserver start ExecStartPost=/usr/local/vpnserver/setup_vpnserver.sh ExecStop=/usr/local/vpnserver/vpnserver stop [Install] WantedBy=multi-user.target
そのあと、次のコマンドを実行
# cd /usr/local/vpnserver/ # chmod 600 * # chmod 700 vpncmd # chmod 700 vpnserver # chmod 700 setup_vpnserver.sh # firewall-cmd --add-port=500/udp --permanent # firewall-cmd --add-port=4500/udp --permanent # firewall-cmd --add-port=5555/tcp --permanent # firewall-cmd --zone=public --add-masquerade --permanent # firewall-cmd --reload
※SoftEtherのコンフィグ(vpn_server.config)はあらかじめ作っておいて、/usr/local/vpnserver/vpn_server.configにアップロード