OpenSSH : パスワード認証2025/08/11 |
|
SSH サーバーを構成し、リモート端末からサーバーに接続して操作できるようにします。なお、SSH は 22/TCP を使用します。 |
|
| [1] | Debian の OpenSSH サーバーはデフォルトでパスワード認証方式でのログインは可能となっています。 さらに root ユーザーのみに関しては [PermitRootLogin prohibit-password] と設定されており、パスワード認証は禁止となっています。 よって、デフォルトのままでも最低限必要な設定はしてある状態ですが、root ユーザーの SSH ログインを一切禁止するのであれば、以下のように設定を変更しておけばよいでしょう。 |
|
root@dlp:~#
apt -y install openssh-server
root@dlp:~#
vi /etc/ssh/sshd_config # 33行目 : コメント解除して [no] に変更すると root ログイン一切禁止 PermitRootLogin no
systemctl restart ssh |
SSH クライアントの設定 : Debian |
|
SSH クライアントの設定です。Debian を例にします。 |
|
| [2] | SSH クライアントをインストールします。 |
|
root@client:~# apt -y install openssh-client
|
| [3] | 任意の一般ユーザーで SSH サーバーに接続します。 |
|
# ssh [ログインユーザー@ホスト名 または IP アドレス] debian@client:~$ ssh debian@dlp.srv.world The authenticity of host 'dlp.srv.world (10.0.0.30)' can't be established. ED25519 key fingerprint is SHA256:CH6c2yxTWxqmciVV1P1uDl3jwqKYsJFL3Iwa/fc5wKw. This key is not known by any other names. Are you sure you want to continue connecting (yes/no/[fingerprint])? yes Warning: Permanently added 'dlp.srv.world' (ED25519) to the list of known hosts. debian@dlp.srv.world's password: Linux dlp.srv.world 6.12.38+deb13-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.12.38-1 (2025-07-16) 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. debian@dlp:~$ # ログインできた |
| [4] | SSH コマンドの引数にコマンドを指定することで、リモートホストで任意のコマンドが実行可能です。 |
|
# 例としてリモートホストの [/etc/passwd] を [cat] する debian@client:~$ ssh debian@dlp.srv.world "cat /etc/passwd" debian@dlp.srv.world's password: root:x:0:0:root:/root:/bin/bash daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin bin:x:2:2:bin:/bin:/usr/sbin/nologin sys:x:3:3:sys:/dev:/usr/sbin/nologin sync:x:4:65534:sync:/bin:/bin/sync games:x:5:60:games:/usr/games:/usr/sbin/nologin man:x:6:12:man:/var/cache/man:/usr/sbin/nologin ..... |
SSH クライアントの設定 : Windows #1 |
|
SSH クライアントの設定です。Windows を例にします。 |
|
| [5] |
Windows クライアント側で SSH で接続可能なソフトウェアを用意します。 一般的には TeraTerm Pro や Putty 等が有名です。 当例では Putty を使用します。 Putty を上記サイトからダウンロード/インストールして起動したら、以下のような画面になるので、 Hostname にサーバーの ホスト名 または IP アドレスを入力し [Open] をクリックして接続します。 |
|
| [6] | ユーザー名とパスワードを入力して認証すると、以下のように Debian サーバーにリモートログインすることができます。 |
|
SSH クライアントの設定 : Windows #2 |
| [7] | Windows には OpenSSH クライアントが標準で実装されています。 これにより、Putty 等の SSH クライアントを用意しなくとも、Windows の標準機能で SSH サーバーへ接続可能です。 |
|
| Sponsored Link |
|
|