ユーザ用ツール

サイト用ツール


サイドバー

Index

はじめてのおつかい






DokuWiki整形記法


PlayGround



serverapps:security:ssh

文書の過去の版を表示しています。


SSH

rootログインの禁止

CentOSなどはデフォルトで許可されているので注意

# cat /etc/ssh/sshd_config | grep Permit
PermitRootLogin no

パスワードログインを禁止して公開鍵認証

認証用のKeyの作成

認証用の秘密鍵と公開鍵のペアが作成される

$ cd
$ ssh-keygen -t rsa -b 4096 

公開鍵をリモートホストのauthorized_keysに追加

$ cat ./.ssh/id_rsa.pub | ssh user@remote_host "cat >> ./.ssh/authorized_keys"

.sshディレクトリがないと失敗するのでその場合には

$ ssh user@remote_host "mkdir ./.ssh && chmod 700 ./.ssh"

とかやってディレクトリを作っておく。

CentOSならssh-copy-idが入っているのでそちらを使うも良し。FreeBSDはPortsのsecurity/ssh-copy-idでインストールしても良いのですがpkgngにはありません。1)

$ ssh-copy-id -i .ssh/id_rsa.pub user@remote_host

なお、authorized_keysはPermissionを 600にしておかないとLogin に失敗するので注意

パスワードログインを禁止

# cat /etc/ssh/sshd_config
......
PasswordAuthentication no
ChallengeResponseAuthentication no
UsePAM no

FreeBSDは標準でPasswordAuthentication を禁止しているがChallengeResponseAuthentication は許可されているのでこちらも必ず「No」にしておく。

公開鍵認証をON

PubkeyAuthentication yes

AuthorizedKeysFile .ssh/authorized_keys

AuthorizedKeysFileを指定すると、このマシンから他へssh接続する際にBad configuration option: AuthorizedKeysFileと表示して落ちます。2)

user's configuration file

.ssh/configファイルで複数サーバーのSSH接続を管理

Host example
  HostName     example.com
  Port         10022
  User         nanako
  IdentityFile ~/.ssh/id_rsa.example

これで以下のようにアクセス可能

$ ssh example

秘密鍵から公開鍵を生成する

ssh-keygen -y -f ~/.ssh/id_rsa > ~/.ssh/id_rsa.pub

公開鍵からfinger printを生成する

ssh-keygen -lf ~/.ssh/id_rsa.pub
1)
2014/12/05現在
2)
昔は生きていたはずで、その為このオプションを指定するよう説明しているサイトや書籍多数です…
serverapps/security/ssh.1493713758.txt.gz · 最終更新: 2017/05/02 17:29 by hayashi