R.A. Epigonos et al.

[ssh] インストールから初期設定まで

sshデーモンのインストール、初期設定、公開鍵認証で接続。sshを使うことで、セキュアな接続、コマンドの実行(ssh)、ファイルコピー(scp)、透過的なファイル操作(sshfs)等、一通り欲しい機能が簡単に手に入るという意味では必須だと思う。

まずはリモート側に ssh サーバをインストール。

# apt-get --no-install-recommends install openssh-server

ローカルの公開鍵認証用の公開鍵 ~/.ssh/id_rsa.pub をリモートの ~/.ssh/authorized_keys に追加。この作業は後述するパスワード認証の禁止が有効化される前に終わらせる。~/.ssh のパーミッションを 700 にして、~/.ssh/authorized_keys のパーミッションを 600 にすることを忘れない。

$ ssh -l hoge *********************** 'mkdir --mode 700 --parents ~/.ssh/; cat >> ~/.ssh/authorized_keys' < ~/.ssh/id_rsa.pub
The authenticity of host '*********************** (**************)' can't be established.
ECDSA key fingerprint is ***********************************************.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '***********************,**************' (ECDSA) to the list of known hosts.
hoge@***********************'s password:
$ ssh -l hoge *********************** 'chmod 700 ~/.ssh; chmod 600 ~/.ssh/authorized_keys;'

後はsshでログインしてrootになって設定作業。

$ ssh -l hoge ***********************
Enter passphrase for key '/*******/.ssh/id_rsa':
Linux ********** 3.2.0-4-amd64 #1 SMP Debian 3.2.41-2+deb7u2 x86_64

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Tue Jun  4 18:26:03 2013 from ****************************
$ su -
Password:
#

よくある設定(rootログインの禁止、パスワード認証の禁止、空パスワードの禁止、ログインユーザの制限(hogeだけ))を行う。

# cat <<EOT >> /etc/ssh/sshd_config
# --------------------------------
PermitRootLogin no
PasswordAuthentication no
PermitEmptyPasswords no
AllowUsers hoge
# --------------------------------
EOT

設定内容を反映させるための ssh デーモンの再起動。再起動は以下のどちらか。

# /etc/init.d/ssh restart
Restarting OpenBSD Secure Shell server: sshd.
# systemctl restart sshd

リファレンス

  1. 公開鍵ファイルauthorized_keysの設置場所とパーミッション | Weblogy
  2. SSHが鍵認証されないとき、パーミッションを疑え。 - それマグで!

ソーシャルブックマーク

  1. はてなブックマーク
  2. Google Bookmarks
  3. del.icio.us

ChangeLog

  1. Posted: 2010-07-26T15:09:10+09:00
  2. Modified: 2010-07-26T15:09:10+09:00
  3. Generated: 2023-08-27T23:09:14+09:00