# Mac 简单配置不同 host 的 ssh-key **Published by:** [BKSN](https://paragraph.com/@bksn/) **Published on:** 2025-04-27 **URL:** https://paragraph.com/@bksn/mac-host-ssh-key ## Content 1. 生成新 SSH 密鑰ssh-keygen -t id_ed25519 -C "your_email@example.com" 如果不命名,默認名是 id_ed25519,一路回車。如果你用的是舊系統,可以使用 rsa 替代 ed25519。這時候會自動創建 .ssh 文件夾。2. 進入文件夾cd ~/.ssh 3. 將新的 ssh-key 添加到 ssh-agentssh-add ~/.ssh/id_ed25519 4. 保存公鑰到托管服務,譬如 GitHubpbcopy < ~/.ssh/id_ed25519.pub 粘貼到 Github 的這個位置: 頭像 -> Settings -> SSH and GPG keys -> New SSH key5. 在不同的 host 中配置vi config 點擊鍵盤 i 鍵入以下資料# github Host github.com HostName github.com PreferredAuthentications publickey IdentityFile ~/.ssh/id_ed25519 # bitbucket Host bitbucket.org HostName bitbucket.org PreferredAuthentications publickey IdentityFile ~/.ssh/bitbucket_ id_ed25519 按 esc 編輯模式,鍵入 :wq 保存。6. 測試一下ssh -T git@github.com 如果顯示下面的提示就是成功了,如果沒有可能就要看一下上面的步驟有沒有出錯Hi <user_name>! You've successfully authenticated, but GitHub does not provide shell access. 祝編程愉悅! ## Publication Information - [BKSN](https://paragraph.com/@bksn/): Publication homepage - [All Posts](https://paragraph.com/@bksn/): More posts from this publication - [RSS Feed](https://api.paragraph.com/blogs/rss/@bksn): Subscribe to updates