長く放置してた ConoHa の VPS インスタンスをまっさらにして1から作り直したときのメモ。(CentOS 7.6)
たまにしかやらないのでログを残しておく。
インスタンス生成

ここの「オプションを見る」を開いた先の「SSH Key」で「キーを選択」すると、事前に設定済みの公開鍵を選べる。

これを選ぶと、 /root/.ssh/authorized_keys
が作成されて公開鍵認証のみで接続できるインスタンスが生成される。( PasswordAuthentication no
)
通常ユーザ作成
※ 以下の sfus
は自分のユーザ名に変えること。
# ssh ログイン
[[email protected]]$ ssh [email protected]
# ユーザー作成
[[email protected]]# adduser sfus
# ユーザのパスワード設定
[[email protected]]# passwd sfus
# wheelグループに追加
[[email protected]]# gpasswd -a sfus wheel
# 作成したユーザでログインできるか確認
[[email protected]]# su sfus
[[email protected]]$
作成したユーザで ssh 公開鍵認証できるようにする (root の公開鍵をコピーする)
[[email protected]]# cp -a ~/.ssh /home/sfus/
[[email protected]]# chown -R sfus:sfus /home/sfus/.ssh/
ローカルから接続
rootからのログインを禁止 & ポートを変更する
[[email protected]]$ sudo vim /etc/ssh/sshd_config
------------------------------------------------------------
# デフォルト 22 となってるのを好みのポート番号に変える
#Port 22
Port 10022
# yes を no に変える
PermitRootLogin no
------------------------------------------------------------
# sshdを再起動する
[[email protected]]$ sudo systemctl restart sshd.service
firewalld の設定変更
# 確認
[[email protected]]$ sudo firewall-cmd --list-ports --zone=public
# ポート追加
[[email protected]]$ sudo firewall-cmd --add-port=10022/tcp --zone=public --permanent
# firewalld 再起動
[[email protected]]$ sudo firewall-cmd --reload
success
# 確認
[[email protected]]$ sudo firewall-cmd --list-ports --zone=public
10022/tcp
ローカルから接続
[[email protected]]$ ssh [email protected] -p 10022
[[email protected]]$
以上