因為經常會用到但是又忘記,所以先把步驟記錄下來
首先,打開 Terminal (或 bash for Windows)
ls ~/.ssh/id_ed25519.pub
# 如果不存在的話
ssh-keygen -t ed25519
# 假設 RPI 的 IP 地址是 192.168.0.14
ssh-copy-id [email protected]
之後應該就可以透過 Claude Code 連接了。但是如果出現下面的 Error ,可能是因為你的 Pi IP 有出現過變動(在 DHCP 網絡環境下常見),所以需要先把舊的 key 刪掉再複制新的過去。
$ ssh-copy-id [email protected]
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "{your_home_path}/.ssh/id_ed25519.pub" /usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed /usr/bin/ssh-copy-id: ERROR: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ERROR: @ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @ ERROR: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ERROR: IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
ERROR: Someone could be eavesdropping on you right now (man-in-the-middle attack)! ERROR: It is also possible that a host key has just been changed. ERROR: The fingerprint for the ED25519 key sent by the remote host is ERROR: SHA256:iksxxxxxxxxxxxxxxxxxxxxxxxxxxxxxOKBDTtA.
ERROR: Please contact your system administrator. ERROR: Add correct host key in {your_home_path}/.ssh/known_hosts to get rid of this message.
ERROR: Offending ECDSA key in {your_home_path}/.ssh/known_hosts:13
ERROR: Host key for 192.168.0.14 has changed and you have requested strict checking. ERROR: Host key verification failed.
解決方法
ssh-keygen -R 192.168.0.14
ssh-keygen -f {your_home_path}/.ssh/known_hosts -R 192.168.0.14
ssh-copy-id [email protected]
# 然後應該會看到
# Are you sure you want to continue connecting (yes/no/[fingerprint])?
# 選 yes
這樣就可以透過 Claude Code 進行連線了。