備忘録です。
(1) 公開鍵・秘密鍵の作成
Teratermで作成、Puttygenでも可。
- TeraTerm メニューの[Setup]から[SSH KeyGenerator…]をクリック
- [Key type:] RSA / [Key Bits:] 2048、[Generate]をクリック。
([bcrypt KDF format]/[Number of rounds]はデフォルトのまま) - [Key passphrase:]および[Confirm passphrase:]をそれぞれ入力、
[Commnet:] 鍵の利用用途を入力 - [Save public key]をクリック、ファイル出力(公開鍵)id_rsa.pub
- [Save private key]をクリック、ファイル出力(秘密鍵)id_rsa
(2) 公開鍵の登録
SSHログインを許可するユーザーのホームディレクトリに公開鍵を登録します。
mkdir ~/.ssh
chmod 700 ~/.ssh
vi ~/.ssh/authorized_keys入力イメージ:(1)にて作成した公開鍵を authorized_keysへ入力します。
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAvdBaczgCBhyk+1tH6/s/2+Gcme5mAulkj2s/xvP1T75r
SX5435iXYSctnrThrbRB2sdaIAJSL4ukFJM9dsRLFzsyYN4ktsVlk6DD1dauW20pAUI6G9ex7Wabgzzf
9r3hxYPzkS/GRagCECPefFYaWXhu2t/58mGSVPCXcT3oH4OJ8vSpOi9OQhThYqlKjtzP4vcGG9WbenU9
NYSF31fCPBoDBR32kYFepX6trMqrsZpjbeF5M1mUpZ+dSZqwosaflMOhnC2zbP7GMrGak2g2yvPLSBJ5
/34kCTP8N4mpXa5QTLxUq7koPBxJjx28PX0XWHLV+/r4iZdBbyaGD6XDnZZ= exiv3@Triton保存後、パーミッションを変更します。
chmod 600 ~/.ssh/authorized_keys(3) sshd設定
sshdパラメータ設定。
sudo vi /etc/ssh/sshd_configSyslogFacility AUTHPRIVに変更します。PermitRootLogin noを追加します。
PubkeyAuthentication yesに変更します。AuthorizedKeysFile コメントアウトを解除します。
SyslogFacility AUTHPRIV
PermitRootLogin no
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keysPasswordAuthentication/ PermitEmptyPasswords/ChallengeResponseAuthentication/UsePAM
をnoに変更します。
PasswordAuthentication no
PermitEmptyPasswords no
ChallengeResponseAuthentication no
UsePAM no変更を保存。サービス再起動します。
[gxuser@localhost ~]$ sudo systemctl restart sshd.service
[gxuser@localhost ~]$ sudo systemctl status sshd.service
● sshd.service - OpenSSH server daemon
Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor pres>
Active: active (running) since Sat 2023-05-06 22:23:22 JST; 8s ago
Docs: man:sshd(8)
man:sshd_config(5)
Main PID: 2994 (sshd)
Tasks: 1 (limit: 23110)
Memory: 1.7M
CPU: 16ms
CGroup: /system.slice/sshd.service
└─2994 "sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups"


コメント