ssh-add を使う
unix
Published: 2019-10-22

やったこと

ssh-add について調べます。

確認環境

$ man ssh-add --help
man, version 1.6c

調査

man より抜粋

DESCRIPTION ssh-add adds private key identities to the authentication agent, ssh-agent(1). When run without arguments, it adds the files ~/.ssh/id_rsa, ~/.ssh/id_dsa, ~/.ssh/id_ecdsa, and ~/.ssh/id_ed25519. After loading a private key, ssh-add will try to load corresponding certificate information from the filename obtained by appending -cert.pub to the name of the private key file. Alternative file names can be given on the command line.

ssh コマンドを使うとき、パスフレーズの入力をスキップ出来ます。

秘密鍵の登録

$ ssh-add ~/.ssh/id_rsa
Enter passphrase for /Users/hogehoge/.ssh/id_rsa:
Identity added: /Users/hogehoge/.ssh/id_rsa (/Users/hogehoge/.ssh/id_rsa)

$ ssh-add -l
2048 SHA256:xxxxxxxxxxx /Users/hogehoge/.ssh/id_rsa (RSA)

秘密鍵の削除

$ ssh-add -d ~/.ssh/id_rsa
Identity removed: /Users/hogehoge/.ssh/id_rsa (hogehoge@hogehoge-no-MBP)

$ ssh-add -l
The agent has no identities.

キーチェーンに保存する

-K      When adding identities, each passphrase will also be stored in the user's keychain.  When removing identities with -d, each passphrase will be
        removed from it.

参考