====== OpenSSH サーバのインストール ======
SSHサーバの設定を変更してセキュリティを強化する。
===== 環境 =====
* Ubuntu
* Ubuntu 14.04.1 LTS 64bit
* openssh-server
* 1:6.6p1-2ubuntu2
===== インストールと設定 =====
SSHサーバがインストールされていない場合はインストールする。
$ sudo apt-get install openssh-server
SSHの設定ファイルは /etc/ssh/sshd_config にある。とりあえずコピーしてオリジナルを保存しておく。
$ cd /etc/ssh/
$ sudo cp ./sshd_config ~/backup/etc/ssh/sshd_config.original
/etc/ssh/sshd_config
を編集
$ sudo vi sshd_config
==== 変更点 ====
* Port 5555
* ポートを変更してセキュリティ強化
* PermitRootLogin no
* rootの直接ログインを拒否
* PasswordAuthentication no
* パスワードのみのログインを拒否
* AllowUsers foo
* SSHログインを許可するユーザを限定
$ diff ~/backup/etc/ssh/sshd_config.original /etc/ssh/sshd_config
5a6
> Port 5555
28c29,30
< PermitRootLogin without-password
---
> #PermitRootLogin without-password
> PermitRootLogin no
52a55
> PasswordAuthentication no
88a92,99
>
>
> # Added by admin begin
> AllowUsers foo
>
> # Added by admin end
>
>
===== ログイン用公開鍵の設置 =====
Puttyやなんかで作った公開鍵(例: hogehoge.pub)をホームディレクトリにコピーし、
SSHの認証用に変換する
$ cd ~/
$ mkdir ./.ssh
$ ssh-keygen -i -f ./hogehoge.pub > ./.ssh/authorized_keys
パーミッション変更
$ chmod 700 ./.ssh/
$ chmod 600 ./.ssh/authorized_keys
設定と公開が気の設置が終わったら保存してSSHの設定をリロード
$ sudo service ssh restart