LoginSignup
1
1

More than 3 years have passed since last update.

ubuntuのVPSを契約したら、すぐにやること

Posted at

ubuntuのVPSを契約したらやること(2021年3月版)

セキュリティなどの観点・近年の鍵交換の主砲から、簡単にインストールができるようになってきました。
そこで2021年版のVPS契約後~最低限のインストールの方法までを書き残しておきます。
何かミスやバージョン違いでエラー等がありましたら、ご連絡お願いします。

  1. ユーザーの作成
  2. ssh鍵の用意
  3. sshdの設定
  4. ファイアウォール設定
  5. 再起動
  6. 設定確認
  7. fishのインストール
  8. 開発環境のセットアップ

ユーザーの作成

# ユーザーを作成する
adduser user_name

# sudoを使えるようにする
gpasswd -a user_name sudo

鍵を用意する

公開鍵をgithubにアップロードしている前提です。
(アップロードしてあるとhttps://github.com/{{username}}.keys から鍵をみることができます)

su user_name
mkdir ~/.ssh 
# githubからダウンロードします。
curl https://github.com/{{username}}.keys > ~/.ssh/authorized_keys
# 権限設定
sudo chmod 600 ~/.ssh/authorized_keys
exit

sshの設定を変更しましょう。

nano /etc/ssh/sshd_config
/etc/ssh/sshd_config
- Port 22
+ Port 2222

- PermitRootLogin prohibit-password
+ PermitRootLogin no

- #PasswordAuthentication yes
+ PasswordAuthentication no

ファイアウォールの設定

bash
sudo ufw allow 2222 # ← 上記で設定したポート
sudo ufw enable

再起動

reboot

設定確認

設定が終わったら、PCからSSHしてみましょう。

ssh -p 2222 username@ipaddress

設定確認

ログインができたら、使う予定のshellなどをインストールしましょう。
fishを入れるのがおすすめ

bash
sudo apt-add-repository ppa:fish-shell/release-3
sudo apt-get update
sudo apt-get install fish
# 末尾に /usr/local/bin/fish を追加
sudo nano /etc/shells
chsh -s /usr/local/bin/fish

終わりに

ちょっと覚書っぽく、書き殴ってしまいましたが、セキュリティは最低限抑えましょう。
fishは最高。寿司食えんけど。

参考文献

1
1
0

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
1
1