Ubuntu Server 20.04をインストールした際、SSHサーバーをインストールすると、GitHubかLaunchpadのアカウントに設定した公開鍵をダウンロードして、SSH接続をID・パスワード認証から公開鍵認証方式に切り替えることができます。
インストール時にしかできないというわけではなく、いくつかの方法で信頼する公開鍵を追加することができます。
Linuxのssh-import-idコマンド
一つは、UbuntuをはじめLinuxディストリビューションに搭載されている「ssh-import-id」コマンド群です。
- ssh-import-id
- ssh-import-id-gh
- ssh-import-id-lp
の3種類あり、ghはGitHub、lpはLaunchpadからのインストールで、無印の場合は引数でgh:もしくはlp:をつければOKのようです。
既にあるキーはインポートされずにそのままです。
ssh-import-idコマンドの挙動を手作業で
WindowsのSSHにはssh-import-idコマンドはありませんし、GitHub、Launchpad以外はサポートされていません。
コマンドの説明に書かれている通り、
This utility will securely contact a public keyserver and retrieve one or more user’s
public keys, and append these to the current user’s ~/.ssh/authorized_keys file, standard
output or any other specified output file.User IDs can be prepended by a protocol:
– lp: to use https://launchpad.net/~%s/+sshkeys
– gh: to use https://api.github.com/users/%s/keysIf the protocol is not explicitly specified, then ssh-import-id will read a URL variable
string from /etc/ssh/ssh_import_id as installed by your package manager and configured by
your system administrator. You can override this locally by exporting the string you want
in a URL environment variable. If all of these are empty, then the protocol is assumed to
be “lp:”, which was the original target implementation of this tool.Any keys added will be “labled” with a trailing comment, “# ssh-import-id PROTO:USER_ID”.
Revoking keys will first look for lines in the authorized keys file ending with that
label.
ホームディレクトリ下の~/.ssh/authorized_keysファイルに追記するコマンドのようです。読込先は、launchpadではhttps://launchpad.net/~%s/+sshkeys、GitHubではhttps://api.github.com/users/%s/keys(それぞれ%sがユーザーID)に公開されている公開鍵だそうです。公開鍵なので漏れてもいいのですが・・・。
インポートするGitHub上の公開鍵は、もともと公開鍵を作成する際にセットされているコメントが削除されてしまい、gh:ユーザー名となってしまうので、GitHub経由でインポートした鍵だということしかわからなくなるのが難点かもしれません。
コメント