Conohaを借りて最初にやったこと


はじめに

いままで自宅サーバーで色々やっていたのですが、前からConohaが気になっていてとりあえず借りてみたので最初にやった設定などのメモをだね

環境

  • Ubuntu 16.04.1 LTS

やること

  • SSHパスワード認証設定
  • ユーザー作成
  • SSH公開鍵作成および受け渡し
  • 鍵認証設定
  • その他SSH関連設定

SSHパスワード認証設定

パスワード認証設定

  • Ubuntu 16.04.1はデフォルトでパスワード認証が無効のため、WEBコンソール画面からパスワード認証を有効にする

WEBコンソールの起動

  • サーバーのコンソールアイコンをクリック

WEBコンソールが起動するのでログインを実施

sshd_configを編集

/etc/ssh/sshd_config
- PasswordAuthentication no
+ PasswordAuthentication yes
- #AuthorizedKeysFile     %h/.ssh/authorized_keys 
+ AuthorizedKeysFile     %h/.ssh/authorized_keys 

sshdサービスの再起動も忘れずに!

$ service sshd restart

SSHで接続できることを確認

$ ssh root@<ip address>

ユーザー作成

ユーザーの作成

root@ubuntu:~# adduser tocyuki
Adding user `tocyuki' ...
Adding new group `tocyuki' (1000) ...
Adding new user `tocyuki' (1000) with group `tocyuki' ...
Creating home directory `/home/tocyuki' ...
Copying files from `/etc/skel' ...
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Changing the user information for tocyuki
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@ubuntu:~# gpasswd -a tocyuki sudo
Adding user tocyuki to group sudo

SSH公開鍵作成および受け渡し

クライアント(ローカル)でSSHキーの作成

~/.ssh/conohaディレクトリを指定して作成する
$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): /root/.ssh/conoha/id_rsa
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/conoha/id_rsa.
Your public key has been saved in /root/.ssh/conoha/id_rsa.pub.
The key fingerprint is:
eb:ea:f3:18:0d:30:54:c8:eb:2a:33:f2:ac:81:81:82 [email protected]
The key's randomart image is:
+--[ RSA 2048]----+
|   ..o.          |
|   .o            |
|    o.           |
|o   .o           |
|E  .  . S        |
|o.  .  o .       |
|o  .  . o        |
|=o.   .+         |
|o*o  .++o        |
+-----------------+

作成した公開鍵をConohaサーバーへアップする

  • コピペもしくはscpコマンドでサーバーへ公開鍵をアップします
$ scp -p ~/.ssh/conoha/id_rsa.pub username@<ip address>:~/.ssh/authorized_keys

鍵認証設定

ssh_configの設定(クライアント側の設定)

/etc/ssh/ssh_config
+ Host <conoha server hostname>
+   HostName <IP or FQDN>
+   User tocyuki
+   Port 22
+   IdentityFile ~/.ssh/conoha/id_rsa

SSH鍵認証でログインできることを確認

$ ssh <conoha server hostname>
Welcome to Ubuntu 16.04.1 LTS (GNU/Linux 4.4.0-57-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

149 packages can be updated.
56 updates are security updates.


Last login: Mon Jun  5 15:57:49 2017 from xxx.xxx.xxx.xxx
tocyuki@ubuntu:~$

その他SSH関連設定(Conohaサーバー)

パスワード認証の無効化

  • さきほど有効にしたパスワード認証設定を再び無効化し、鍵認証でのみログインできるようにします。
/etc/ssh/sshd_config
- PasswordAuthentication yes
+ PasswordAuthentication no

SSHサービスポートの変更

  • SSHのデフォルトポートを変更します
    クライアント側の/etc/ssh/ssh_configの設定も併せて修正すること
/etc/ssh/sshd_config
- Port 22
+ Port 10022

おわりに

ここからDocker入れてみたり色々してみたいと思います\(^o^)/