目次

概要

ESXiへの自動ログインなどを行うためのSSH鍵の追加手順

前提

以下の作業は事前に済ませてあることを前提とする。

手順

ESXiでは以下の場所にSSH公開鍵(authorized_keys)を配置する。

/etc/ssh

rootのSSH鍵の場合は以下となる。

/etc/ssh/keys-root



以下の手順にてrootユーザ向けのSSH公開鍵を配置する。

1. 公開鍵をESXiサーバに転送
2. 公開鍵のサイズを確認

# ls -la /etc/ssh/keys-root 
total 8
drwxr-xr-x    1 root     root           512 Sep 26 15:06 .
drwxr-xr-x    1 root     root           512 Sep 26 15:06 ..
-rw------T    1 root     root             0 Sep 19  2013 authorized_keys


3. 公開鍵を書き込み

cat [公開鍵ファイル] > /etc/ssh/keys-root/authorized_keys


4. 公開鍵のサイズを確認

# ls -la /etc/ssh/keys-root
total 12
drwxr-xr-x    1 root     root           512 Sep 28 02:43 .
-r-------T    1 root     root             0 Sep 19  2013 .#authorized_keys
drwxr-xr-x    1 root     root           512 Sep 26 15:06 ..
-rw------T    1 root     root           407 Sep 28 02:43 authorized_keys


5. 別のホストから接続を確認

# ssh -l root -i [SSH秘密鍵] [ESXiホスト]
The time and date of this login have been sent to the system logs.

VMware offers supported, powerful system administration tools.   Please
see www.vmware.com/go/sysadmintools for details.

The ESXi Shell can be disabled by an administrative user. See the
vSphere Security documentation for more information.
~ #

トラブル対応

初回アクセス時の注意事項

SSHの仕様により、known_hostsにフィンガープリントが記録されていないサーバにアクセスすると以下のメッセージが表示されて判断待ちとなる。

The authenticity of host '[HOSTNAME] ([IP])' can't be established.
RSA key fingerprint is 87:17:4b:b1:36:a5:8b:47:55:c1:51:5e:f5:14:f7:2f.
Are you sure you want to continue connecting (yes/no)?


プログラムにて自動ログインを行う場合には支障となることから、プログラムを実行するユーザからSSH接続を行い、フィンガープリントを記録させる必要がある。

フィンガープリントの不一致

ESXiの再インストールを行う等を行った場合、過去に接続した際のフィンガープリントと不一致が発生して以下のエラーが表示される。

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that the RSA host key has just been changed.
The fingerprint for the RSA key sent by the remote host is 87:17:4b:b1:36:a5:8b:47:55:c1:51:5e:f5:14:f7:2f.
Please contact your system administrator.
Add correct host key in /home/[USER]/.ssh/known_hosts to get rid of this message.
Offending key in /home/[USER]/.ssh/known_hosts:2
RSA host key for [ESXi IP] has changed and you have requested strict checking.
Host key verification failed.



上記のメッセージに記載されている通り、/home/[USER]/.ssh/known_hosts に記載された古いフィンガープリントを削除する必要がある。
(vi等で上記ファイルを開き、当該ホストの行を削除する)


トップ   編集 凍結 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2025-03-16 (日) 23:18:07