今後ログインしない場合は、ホストキーを削除しておきます。
SSHログイン前の変数が保持されていることを確認します。
変数の確認 cat << END # EC2_IP_PUBLIC:"xxx.xxx.xxx.xxx" EC2_IP_PUBLIC="${EC2_IP_PUBLIC}" # PORT_SSHD:"22022" PORT_SSHD="${PORT_SSHD}" END
変数の確認
cat << END # EC2_IP_PUBLIC:"xxx.xxx.xxx.xxx" EC2_IP_PUBLIC="${EC2_IP_PUBLIC}" # PORT_SSHD:"22022" PORT_SSHD="${PORT_SSHD}" END
~/.ssh/known_hostsからEC2インスタンスのホストキーを削除します。
コマンド: ssh-keygen -R "[${EC2_IP_PUBLIC}]:${PORT_SSHD}" 結果(例): # Host xxx.xxx.xxx.xxx found: line 2 /home/ec2-user/.ssh/known_hosts updated. Original contents retained as /home/ec2-user/.ssh/known_hosts.old
コマンド:
ssh-keygen -R "[${EC2_IP_PUBLIC}]:${PORT_SSHD}"
結果(例):
# Host xxx.xxx.xxx.xxx found: line 2 /home/ec2-user/.ssh/known_hosts updated. Original contents retained as /home/ec2-user/.ssh/known_hosts.old