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