公開鍵関連の設定を行ったのでメモ.
# 公開鍵関連の設定を行ったのでメモ.
# 鍵の作成
$ mkdir ~/.ssh/PATH/TO/DIR
$ chmod 700 ~/.ssh/PATH/TO/DIR
$ cd ~/.ssh/PATH/TO/DIR
$ ssh-keygen -t rsa -b 2048
$ chmod 600 id_rsa
$ pbcopy < id_rsa.pub
# 接続
$ ssh root@XXX.XXX.XX.XX
# ユーザー作成(ex: admin)とパスワード設定
# sakura, conoha (digitaloceanは作成時にパスワードを入力)
$ adduser admin
$ passwd admin
# wheelグループに追加
# sakura, conoha
$ gpasswd -a admin wheel
# digitalocean
$ gpasswd -a admin sudo
# wheelグループをsudoerに追加
# sakura, conoha
$ sudo vi /etc/sudoers
-- # %wheel ALL=(ALL) ALL
++ %wheel ALL=(ALL) ALL
$ su admin
$ sudo vi /etc/ssh/sshd_config
# sakura, conoha
-- # RSAAuthentication yes
++ RSAAuthentication yes
-- # PubkeyAuthentication yes
++ PubkeyAuthentication yes
-- # PermitRootLogin yes
++ PermitRootLogin no
-- # PasswordAuthentication yes
++ PasswordAuthentication no
# digitalocean
-- # RSAAuthentication yes
++ RSAAuthentication yes
-- # PasswordAuthentication yes
++ PasswordAuthentication no
$ mkdir ~/.ssh/
$ chmod 700 ~/.ssh/
$ touch ~/.ssh/authorized_keys
# コピーしておいた公開鍵を書き込む
$ vi authorized_keys
$ chmod 600 authorized_keys
$ sudo service sshd restart
# iptablesの設定を行う(ex: SSHをport33で行う)
# conoha
$ sudo yum install -y iptables-services
$ sudo vi /etc/sysconfig/iptables
-- -A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
++ -A INPUT -m state --state NEW -m tcp -p tcp --dport 33 -j ACCEPT
# digitalocean
$ sudo apt-get install iptables-persistent
# sakura, digitalocean
$ sudo iptables -I INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
$ sudo iptables -A INPUT -p tcp --tcp-flags ALL NONE -j DROP
$ sudo iptables -A INPUT -p tcp --tcp-flags ALL ALL -j DROP
$ sudo iptables -A INPUT -p tcp ! --syn -m state --state NEW -j DROP
$ sudo iptables -A INPUT -i lo -j ACCEPT
$ sudo iptables -A INPUT -p icmp -j ACCEPT
$ sudo iptables -A INPUT -p tcp -m tcp --dport 33 -j ACCEPT
$ sudo iptables -P INPUT DROP
$ sudo iptables -P OUTPUT ACCEPT
# 確認
$ sudo iptables -L
# sakura, conoha
$ sudo service iptables restart
# digitalocean
$ sudo ufw enable
$ sudo vi /etc/ssh/sshd_config
# Port 22
Port 33
$ sudo service sshd restart
# 必ず他のプロセスでログインを確認する
$ exit