さくらVPSでRailsの環境構築を行った際のメモ。
セットアップ
$ ssh root@xxx.xxx.xxx.xxx
# yum update
# adduser vpsuser
# passwd vpsuser
# exit
$ ssh vpsuser@xxx.xxx.xxx.xxx
$ su -
# usermod -G wheel vpsuser
次回ログイン以降に設定が有効化
$ sudo id
[sudo] password for vpsuser:
uid=0(root) gid=0(root) groups=0(root)
# cd /etc/ssh
# cp sshd_config sshd_config.old
# vim sshd_config
変更前
#PermitRootLogin yes
変更後
PermitRootLogin no
# systemctl restart sshd.service
$ ssh root@xxx.xxx.xxx.xxx
以上で一般ユーザーで接続できるところまで準備できました。
鍵認証設定
$ cat ~/.ssh/id_rsa.pub
$ mkdir .ssh && chmod 700 .ssh && cd .ssh
- .sshディレクトリの下でauthorized_keysを作成し、コピーした公開鍵を貼り付け
$ vim authorized_keys
$ chmod 600 authorized_keys
$ ssh -i ~/.ssh/id_rsa vpsuser@xxx.xxx.xxx.xxx
$ su -
# cd /etc/ssh
# vim sshd_config
変更前
#PasswordAuthentication yes
変更後
PasswordAuthentication no
# systemctl restart sshd.service
パスワードによるログインができないこと、公開鍵認証によるログインができることを確認して完了します。
ssh接続用ポート番号の変更
$ su -
# vim /etc/ssh/sshd_config
#Port 22
Port 10022
# systemctl restart sshd.service
- firewalld の設定ファイルを編集。ポート番号の22の部分を変更。
<?xml version="1.0" encoding="utf-8"?>
<service>
<short>SSH</short>
<description>Secure Shell (SSH) is a protocol for logging into and executing commands on remote machines. It provides secure encrypted communications. If you plan on accessing your machine remotely via SSH over a firewalled interface, enable this option. You need the openssh-server package installed for this option to be useful.</description>
<port protocol="tcp" port="22"/>
</service>
# firewall-cmd --reload
success
$ ssh vpsuser@xxx.xxx.xxx.xxx -p 10022
- Ruby のインストールに必要なライブラリをインストール
$ sudo yum install -y openssl-devel zlib-devel readline-devel libyaml-devel libffi-devel
$ git clone https://github.com/rbenv/rbenv.git ~/.rbenv
$ git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
$ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
$ rbenv install 2.5.3
$ rbenv global 2.5.3
$ rbenv rehash
参考