CentOS Stream 8
Sponsored Link

OpenSSH : パスワード認証2021/02/22

 
SSH サーバーを構成し、リモートコンピューターからサーバーに接続して操作できるようにします。
[1] SSH サーバーは CentOS Stream 最小構成インストールでも、デフォルトで OpenSSH がインストールされ、自動起動設定になっているため、パスワード認証方式でのログインは可能となっています。 ただし、デフォルトでは、root アカウントの直接ログインが可能な設定になっているため、セキュリティを考慮するならば、以下のように root アカウントの直接ログインの禁止設定を実施しておくとよいでしょう。
[root@dlp ~]#
vi /etc/ssh/sshd_config
# 43行目 : 変更 ( root ログイン禁止 )

PermitRootLogin
no
[root@dlp ~]#
systemctl restart sshd

[2] Firewalld を有効にしている場合は、SSH サービスの許可が必要です。SSH は [22/TCP] を使用します。
[root@dlp ~]#
firewall-cmd --add-service=ssh

success
[root@dlp ~]#
firewall-cmd --runtime-to-permanent

success
SSH クライアントの設定 : CentOS
 
SSH クライアントの設定です。CentOS を例にします。
[3] SSH クライアントをインストールします。
[root@node01 ~]#
dnf -y install openssh-clients
[4] 任意の一般ユーザーで SSH サーバーに接続します。
# ssh [ログインユーザー@ホスト名 または IP アドレス]

[cent@node01 ~]$
ssh cent@dlp.srv.world

The authenticity of host 'dlp.srv.world (10.0.0.30)' can't be established.
ECDSA key fingerprint is SHA256:bm8HoSi5APr9Ux0WHiuVDBh9OdvdUGnPagD7fK4xyis.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'dlp.srv.world,10.0.0.30' (ECDSA) to the list of known hosts.
cent@dlp.srv.world's password:
Activate the web console with: systemctl enable --now cockpit.socket
[cent@dlp ~]$   # ログインできた
[5] SSH コマンドの引数にコマンドを指定することで、リモートホストで任意のコマンドが実行可能です。
# 例としてリモートホストの /etc/passwd を cat する

[cent@node01 ~]$
ssh cent@dlp.srv.world "cat /etc/passwd"

cent@dlp.srv.world's password:
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
.....
.....
rngd:x:989:985:Random Number Generator Daemon:/var/lib/rngd:/sbin/nologin
tcpdump:x:72:72::/:/sbin/nologin
cent:x:1000:1000::/home/cent:/bin/bash
SSH クライアントの設定 : Windows #1
 
SSH クライアントの設定です。Windows を例にします。
[6]
Windows クライアント側で SSH クライアント ソフトウェアを用意します。
一般的には TeraTerm (sourceforge.jp/projects/ttssh2/) や Putty (www.chiark.greenend.org.uk/~sgtatham/putty/) 等が有名です。
当例では Putty を使用します。
Putty をダウンロード/インストールして起動後、以下の画面で、 [Host Name] にサーバーの ホスト名または IP アドレスを入力し [Open] ボタンをクリックします。
[7] ユーザー名とパスワードを入力して認証すると、以下のように CentOS サーバーに SSH でリモートログインすることができます。
SSH クライアントの設定 : Windows #2
[8] Windows 10 バージョン 1803 以降を使用中の場合は、OpenSSH クライアントが標準で実装されています。 これにより、Putty 等の SSH クライアントを用意しなくとも、Windows の標準機能で SSH サーバーへ接続可能です。
関連コンテンツ