| OpenSSH : パスワード認証2024/04/26 | 
| 
SSH サーバーを構成し、リモート端末からサーバーに接続して操作できるようにします。なお、SSH は 22/TCP を使用します。 
 | |
| [1] | Ubuntu の 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 クライアントの設定 : Ubuntu | 
| 
SSH クライアントの設定です。Ubuntu を例にします。
 | |
| [2] | SSH クライアントをインストールします。 | 
| root@client:~# apt -y install openssh-client  | 
| [3] | 任意の一般ユーザーで SSH サーバーに接続します。 | 
| # ssh [ログインユーザー@ホスト名 または IP アドレス] root@client:~# ssh ubuntu@dlp.srv.world  
The authenticity of host 'dlp.srv.world (10.0.0.30)' can't be established.
ED25519 key fingerprint is SHA256:6wnWGpzjyIur7FRtJi3sbyGj3JolsRW1sEWC4tNM9ao.
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.
ubuntu@dlp.srv.world's password:
Welcome to Ubuntu 24.04 LTS (GNU/Linux 6.8.0-31-generic x86_64)
.....
.....
ubuntu@dlp:~$# ログインできた | 
| [4] | SSH コマンドの引数にコマンドを指定することで、リモートホストで任意のコマンドが実行可能です。 | 
| # 例としてリモートホストの [/etc/passwd] を [cat] する ubuntu@client:~$ ssh ubuntu@dlp.srv.world "cat /etc/passwd"  ubuntu@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] | ユーザー名とパスワードを入力して認証すると、以下のように Ubuntu サーバーにリモートログインすることができます。 | 
|   | 
| SSH クライアントの設定 : Windows #2 | 
| [7] | Windows には OpenSSH クライアントが標準で実装されています。 これにより、Putty 等の SSH クライアントを用意しなくとも、Windows の標準機能で SSH サーバーへ接続可能です。 | 
|   | 
| Sponsored Link | 
|  |