見出し画像

【IT】Azure LinuxサーバのSSH-Keyリセット

皆さま
こんにちは

Azure上のVirtual MachineのLinuxサーバにログインの際に
SSH-Keyを使用しております。

SSH-Keyの紛失に備えてKeyの入れ替えを行います。

今回は、CentOS8.5を使用しております。

今回の内容


1.SSH-Keyの作成

Azureポータルの画面より
「ホーム」ー「SSHキー」を選択して
新しいSSH-Keyを作成します。

リソースグループは、対象のLinuxサーバと同じグループを選択します。
キーの名前は、わかりやすい名前を付与ください。

必ず新しいキーをダウンロードしておきます。

SSH-Keyが作成できたらキーを開いて公開キーをコピーしておきます。

2.SSH-Keyの登録

対象の仮想マシンの「パスワードのリセット」を選択し、
「SSH 公開キー」のリセットを選択し、
ユーザ名、SSH公開キー(1でコピーした)を貼り付けて
「更新」を押して公開キーの登録を行います。
※ユーザは、今回は、azuretestとしてあります。
 (作成したときのユーザに合わせてください)

新しくダウンロードしたSSH-Key秘密鍵でアクセスできるか確認します。

# ssh -i Test-Rest-key999.pem azuretest@aaa.bbb.ccc.ddd
Activate the web console with: systemctl enable --now cockpit.socket


Thank you for choosing this Microsoft sponsored CentOS image from OpenLogic!
_______                    ______               _____
__  __ \______________________  / _____________ ___(_)______
_  / / /__  __ \  _ \_  __ \_  /  _  __ \_  __ `/_  /_  ___/
/ /_/ /__  /_/ /  __/  / / /  /___/ /_/ /  /_/ /_  / / /__
\____/ _  .___/\___//_/ /_//_____/\____/_\__, / /_/  \___/
       /_/                              /____/  by Perforce
                           ____           _    ___  ____     ___   ____
                          / ___|___ _ __ | |_ / _ \/ ___|   ( _ ) | ___|
                         | |   / _ \ '_ \| __| | | \___ \   / _ \ |___ \
                         | |__|  __/ | | | |_| |_| |___) | | (_) | ___) |
                          \____\___|_| |_|\__|\___/|____/   \___(_)____/
                                                                   (2111)

While OpenLogic support is not including with this image, OpenLogic does
offer Silver (12x5) & Gold (24x7) support options and consulting for
enterprise and/or mission critical systems as well as over 400 open-source
packages.  If interested, email info@perforce.com or call +1 612.517.2100.

Last login: Sun Jul 16 03:49:52 2023 from aaa.bbb.ccc.ddd

3.古いSSH-Keyの削除

新しいSSH-Keyでログインできるようになりましたが
古いKeyでログイン出来てしまいますので失効させます。

Linuxサーバにログイン後、「~/.ssh/authorized_keys」の
元々あるSSH-Keyを削除します。(上側の行)

次にAzureポータル上からも古いKeyを削除します。

「ホーム」ー「SSHキー」で古いキーを選択し削除を選択します。

古いキーでログイン出来ないことを確認します。

 ssh -i Test-Free-lin_key.pem azuretest@aaa.bbb.ccc.ddd
azuretest@aaa.bbb.ccc.ddd: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).


では

この記事が気に入ったらサポートをしてみませんか?