LoginSignup
0
2

More than 3 years have passed since last update.

VPS最初にやること備忘録

Last updated at Posted at 2019-05-02

Ubuntuのバージョンアップ

$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get dist-upgrade
$ sudo reboot
$ sudo apt install ubuntu-release-upgrader-core
$ sudo do-release-upgrade

rootパスワード変更

root@localhost:~# passwd
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully

普段使うユーザーを追加

root@localhost:/home# adduser ninja
Adding user `ninja' ...
Adding new group `ninja' (1000) ...
Adding new user `ninja' (1000) with group `ninja' ...
Creating home directory `/home/ninja' ...
Copying files from `/etc/skel' ...
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Changing the user information for ninja
Enter the new value, or press ENTER for the default
        Full Name []:
        Room Number []:
        Work Phone []:
        Home Phone []:
        Other []:
Is the information correct? [Y/n] y

普段使うユーザーにsudo権限付与

root@localhost:/home# gpasswd -a ninja sudo
Adding user ninja to group sudo

rootログインを無効にする

cd /etc/ssh
vi sshd_config

/*PermitRootLoginをyesからnoに変更する*/
PermitRootLogin no
/*sshを再起動*/
ninja@localhost:/etc/ssh# sudo /etc/init.d/ssh restart

aptのアップデート

ninja@localhost:/etc/ssh# sudo apt-get update
ninja@localhost:~$ sudo apt-get upgrade

鍵認証

/*ローカルで鍵作成*/
$ cd ~
$ mkdir .ssh
$ cd ~/.ssh
$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/ユーザー/.ssh/id_rsa):
/*passphreseは11文字以上にしておく*/
Enter passphrase (empty for no passphrase):
Enter same passphrase again:

サーバーにid_rsa.pubを送る。

ninja@localhost:~$ sudo apt-get install openssh-server
ninja@localhost:~$ mkdir ~/.ssh
ninja@localhost:~$ chmod 700 .ssh
ninja@localhost:~$ touch ~/.ssh/authorized_keys
ninja@localhost:~$ chmod 600 ~/.ssh/authorized_keys
ninja@localhost:~$ cat ~/id_rsa.pub >> .ssh/authorized_keys

パスワード認証を禁止する(必ず鍵認証でログインできることを確認してから行う)

ninja@localhost:~$ sudo vi /etc/ssh/sshd_config

/* 「#PasswordAuthentication yes」を「PasswordAuthentication no」へ変更 */
PasswordAuthentication no

ninja@localhost:~$ sudo service ssh restart
※他のコンソールを開いて入れるか確認する。間違っていると入れなくなるため。

ファイアウォール設定

/* とりあえず、SSH接続のみ許可*/
ninja@localhost:~$ sudo apt-get install ufw
ninja@localhost:~$ sudo ufw allow 3843

ninja@localhost:~$ sudo vi /etc/default/ufw

-   IPV6=yes
+   IPV6=no

ninja@localhost:~$ sudo ufw enable
ninja@localhost:~$ sudo ufw reload

/* 以下のコマンドで確認*/
ninja@localhost:~$ sudo ufw status
0
2
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
0
2