3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

ssh-keyscan コマンドがあるらしい

Posted at

勉強前イメージ

初めて知ったコマンド

調査

ssh-keyscan コマンド とは

複数のホストのsshの公開鍵を収集するためのコマンドです。
複数のホストを指定して実行できるので、known_hostsのファイルを効率よく生成できます。

打ってみる

あるサーバに向けて打ってみました。
コマンドは ssh-keyscan -H [IPアドレス] になります。
-Hは内容のハッシュ化をするオプションです。

[root@localhost ~]# ssh-keyscan -H [IPアドレス]
# [IPアドレス]:22 SSH-2.0-OpenSSH_7.4
|1|YSAANwY9XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
# [IPアドレス]:22 SSH-2.0-OpenSSH_7.4
|1|SNNBcGeSNXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
# [IPアドレス]:22 SSH-2.0-OpenSSH_7.4
|1|Xxd2SuXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

known_hostsへ追加する場合は ssh-keyscan -t rsa [IPアドレス] >> .ssh/known_hosts を使用します。
結果は以下のように無事追加され、これを行うことで初めてsshを行ったとしても
Are you sure you want to continue connecting (yes/no)? を聞かれることはありません。

[root@localhost ~]# ssh-keyscan -t rsa [IPアドレス] >> .ssh/known_hosts 
# 192.168.119.3:22 SSH-2.0-OpenSSH_7.4
[root@localhost ~]# cat .ssh/known_hosts 
192.168.119.3 ssh-rsa DVcRj46JNpkWuaUrPOTmJQxXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

勉強後イメージ

sshで入ってデータ収集して・・・ってシェル書くときに
Are you sure you want to continue connecting (yes/no)? のせいで
あーsshログインしてなかったーってなるからそんなときはいいかも

参考

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?