ユーザ用ツール

サイト用ツール


ubuntu-server-18-04:sshd

差分

このページの2つのバージョン間の差分を表示します。

この比較画面にリンクする

次のリビジョン
前のリビジョン
ubuntu-server-18-04:sshd [2019/08/23 15:07]
admin 作成
ubuntu-server-18-04:sshd [2020/04/09 20:44] (現在)
admin [ログイン用公開鍵の設置]
行 3: 行 3:
 SSHサーバの設定を変更してセキュリティを強化する。 SSHサーバの設定を変更してセキュリティを強化する。
  
-===== 環境 ===== 
  
-  * Ubuntu +===== インストール環境 ===== 
-    * Ubuntu 18.04.3 LTS 64bit + 
-  * openssh-server +  * Ubuntu 18.04.3 LTS 64bit 
-    * 1:7.6p1-4ubuntu0.3 +  * お名前.com VPS (KVM) 1GB プラン 
 + 
 +^ パッケージ名 ^ バージョン ^ 
 +openssh-server 1:7.6p1-4ubuntu0.3 
 + 
  
 ===== インストールと設定 ===== ===== インストールと設定 =====
行 22: 行 26:
 設定ファイルを編集する前にオリジナルの設定ファイルを保存しておく。 設定ファイルを編集する前にオリジナルの設定ファイルを保存しておく。
 <code> <code>
 +$ cd /etc/ssh
 +$ sudo cp ./sshd_config ./sshd_config.original
 +$ sudo chmod a-w ./sshd_config.original
 +</code>
  
 /etc/ssh/sshd_config /etc/ssh/sshd_config
行 27: 行 35:
  
 <code> <code>
-$ sudo vi sshd_config+$ sudo vi ./sshd_config
 </code> </code>
  
行 44: 行 52:
  
 <code> <code>
-$ diff ~/backup/etc/ssh/sshd_config.original /etc/ssh/sshd_config  +$ diff ./sshd_config.original ./sshd_config 
-5a6 +13a14 
-> Port 5555 +> Port 37784 
-28c29,30 +32a34
-< PermitRootLogin without-password +
---- +
-> #PermitRootLogin without-password+
 > PermitRootLogin no > PermitRootLogin no
-52a55+56a59
 > PasswordAuthentication no > PasswordAuthentication no
-88a92,99 +123c126,131 
-+< PasswordAuthentication yes 
 +--- 
 +#PasswordAuthentication yes
  
-> # Added by admin begin 
 > AllowUsers foo > AllowUsers foo
- 
-> # Added by admin end 
- 
  
 </code> </code>
  
 +sshd を再起動して設定を有効化する。
 +
 +<code>
 +% sudo systemctl restart sshd.service
 +</code>
  
 ===== ログイン用公開鍵の設置 ===== ===== ログイン用公開鍵の設置 =====
  
-Puttyなんかで作った公開鍵(例: hogehoge.pubをホームディレクトリにコピーし、 +ローカルのコンピュータで SSH ログイン用の鍵を作成する。 
-SSHの認証用に変換する+Linux や Mac は以下のコマンドで。Windows は Putty 等を利用して成する。 
 + 
 +鍵長が短くても良い場合は "-b 4096" は不要。 
 +<code> 
 +$ ssh-keygen -t rsa -b 4096 -C "Comment of Key" -f ./ssh_key 
 +</code> 
 + 
 +秘密鍵から公開鍵をエクスポート。 
 +<code> 
 +$ ssh-keygen -y -f ./ssh_key > ./id_rsa.pub 
 +</code> 
 + 
 +エクスポートした公開鍵サーバーのホームディレクトリにコピーして利可能にする
  
 <code> <code>
 $ cd ~/ $ cd ~/
 $ mkdir ./.ssh $ mkdir ./.ssh
-ssh-keygen -i -f ./hogehoge.pub > ./.ssh/authorized_keys+cat ./id_rsa.pub >> ~/.ssh/authorized_keys
 </code> </code>
  
-パーミッション変更+セキュリティのためパーミッション変更しておく。
  
 <code> <code>
行 84: 行 104:
 </code> </code>
  
-設定と公開が気の設置が終わったら保存してSSHの設定リロード+===== ファイアフォールの設定 ===== 
 + 
 +SSH ポートへのアクセス許可する。
  
 <code> <code>
-$ sudo service ssh restart+$ sudo ufw allow 5555/tcp
 </code> </code>
- 
  
 ===== 参考 ===== ===== 参考 =====
ubuntu-server-18-04/sshd.1566540445.txt.gz · 最終更新: 2019/08/23 15:07 by admin