ssh-keygen
網路
用法
ssh-keygen -t ed25519 -C "<comment>"產生一對公鑰和私鑰;放到伺服器上的只有 `.pub` 那一半,而不設口令產生的金鑰就是一個普通檔案,誰複製走都能直接登入。
常用選項
| 選項 | 含義 |
|---|---|
| -t ed25519 | Key type. ed25519 is the modern default; rsa needs -b 4096 to be worth using. |
| -C "you@laptop" | A comment so you can tell your keys apart later. |
| -f <path> | Where to write the key, when you want more than one. |
| -N "" | No passphrase. Then the file alone is enough to log in. |
| -p | Change or add the passphrase on an existing key. |
| -l -f <key.pub> | Print the fingerprint, to compare against what a server shows. |
| -y -f <key> | Recreate the public half from a private key. |
| -R <host> | Remove a host from known_hosts after it was rebuilt. |
範例
ssh-keygen -t ed25519 -C "jade@laptop"Create a modern key pair in ~/.ssh.
ssh-keygen -R old.example.comFix the "REMOTE HOST IDENTIFICATION HAS CHANGED" warning properly.
ssh-keygen -lf ~/.ssh/id_ed25519.pubThe fingerprint of your public key.
連不上的時候,這些能把範圍縮小——是名稱解析不了、沒有路由,還是連接埠被擋。
怎麼看
- 方括號 [ ] 表示這部分可以不寫。
- 省略號 … 表示可以寫多個。
- 選項區分大小寫——有些命令裡 -r 和 -R 不是一回事。
常見問題
Q. ssh-keygen 是做什麼的?
產生一對公鑰和私鑰;放到伺服器上的只有 `.pub` 那一半,而不設口令產生的金鑰就是一個普通檔案,誰複製走都能直接登入。
Q. 怎麼寫?
ssh-keygen -t ed25519 -C "<comment>" —— 方括號表示可以省略的部分。
Q. 值得記的選項有幾個?
這裡列了 8 個,完整列表在 man ssh-keygen。這條命令屬於網路。
相關命令
man 手冊: man ssh-keygen