39
19

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 5 years have passed since last update.

sshコマンドで「Load key “(公開鍵のパス)” invalid format」という警告が出る場合

Last updated at Posted at 2018-06-27

発生する問題

~/.ssh/configで管理されているサーバーにsshコマンドで接続したときに、次のような警告が出る場合がある(ただし、接続自体は成功する)。

$ ssh my-server
Load key "/Users/jnito/.ssh/id_rsa.pub": invalid format

原因

~/.ssh/configIdentityFileに秘密鍵(id_rsa)と公開鍵(id_rsa.pub)の2つが指定されている。

~/.ssh/config
Host *
  UseKeychain yes
  AddKeysToAgent yes
  IdentityFile ~/.ssh/id_rsa.pub
  IdentityFile ~/.ssh/id_rsa

Host my-server
  HostName foo-bar.jp
  IdentityFile ~/.ssh/id_rsa.pub
  Port 5419
  User hogehoge

秘密鍵が指定されているので接続には成功するが、公開鍵を指定することには問題があるので警告が出てしまう。

解決策

~/.ssh/configIdentityFileには秘密鍵(id_rsa)だけを指定する。

~/.ssh/config
Host *
  UseKeychain yes
  AddKeysToAgent yes
  IdentityFile ~/.ssh/id_rsa

Host my-server
  HostName foo-bar.jp
  IdentityFile ~/.ssh/id_rsa
  Port 5419
  User hogehoge

参考情報

linux - id_rsa.pub file SSH Error: invalid format - Stack Overflow

39
19
2

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
39
19

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?