それマグで!

知識はカップより、マグでゆっくり頂きます。 takuya_1stのブログ

習慣に早くから配慮した者は、 おそらく人生の実りも大きい。

Macでssh-keygen したら、デフォルト鍵が変わってしまった。ssh-agentを使う。

作業用に別の鍵を作ったんですが。

ssh-keygen -t rsa -b 2048

普段使う鍵の優先度まで変わってしまってマイッタ

id_rsa を使ってほしいのに、作ったid_rsa.spare が優先されてしまう。

takuya@~/.ssh$ ssh-copy-id 192.168.2.112

/usr/local/bin/ssh-copy-id: ERROR: failed to open ID file '/Users/takuya/.ssh/id_rsa.spare': No such file or directory

デフォルトの鍵の優先度

OSX では ssh-agent と ssh-add と Keychain が鍵を管理しているので、新しく鍵を登録しなおせば解決

ssh-add .ssh/id_rsa

無事デフォルトの鍵ファイルで登録できた

takuya@~/.ssh$ ssh-copy-id 192.168.2.1xx
The authenticity of host '192.168.2.1xxx(192.168.2.1xx)' can't be established.
ECDSA key fingerprint is SHA256:NtRxxxx/fiC7TJBxxxxxxxxxxxxx
Are you sure you want to continue connecting (yes/no)? yes
/usr/local/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/local/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
takuya@192.168.2.1xx's password:
Connection closed by 192.168.2.1xx

ssh-agent と ssh-add

OSX では、鍵ファイルと鍵のパスフレーズをKeychainsとssh-agent で自動的に管理してくれている。

takuya@~/.ssh$ ps aux | grep ssh-agent
77:takuya           1754   0.0  0.0  2474148   2188   ??  U     6:34PM   0:00.31 /usr/bin/ssh-agent -l
takuya@~/.ssh$ env | grep -i ssh
13:SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.WPyVNk5mdX/Listeners

普段は殆ど気にに留めない。あまりにも当たり前で動いているので忘れそうになる。ていうか忘れてた

参考資料

https://blog.hello-world.jp.net/mac-2/1445/

http://www.ksknet.net/cat13/sshagent.html