設定 Codeberg SSH 認證
2026-02-23產生一組金鑰
mkdir ~/.ssh
chmod 700 ~/.ssh
ssh-keygen -t ed25519 -f codeberg_key -C "address@your_mail.com"
# ssh-keygen -t rsa -b 4096 -C "address@your_mail.com"
# -t: encryption algorithm, default rsa
# -f: file name of the key-pair, default id_rsa, id_rsa.pub
# -P: old password
# -N: new password
# -b: key length
# -C: label
Generating public/private ed25519 key pair.
Enter file in which to save the key (/home/username/.ssh/codeberg_key): # file path & name
Enter passphrase (empty for no passphrase): # keep empty
Enter same passphrase again:
將公鑰貼到 Codeberg 的 SSH / GPG Keys 設定裡面
cat ~/.ssh/codeberg_key.pub
設定 SSH 自動取用對應的金鑰
nano ~/.ssh/config
Host codeberg.org
User git
Hostname codeberg.org
IdentityFile ~/.ssh/codeberg_key
測試
ssh -T git@codeberg.org
# Hi there, zhhsieh! You've successfully authenticated with the key named zhh@noreply.codeberg.org, but Forgejo does not provide shell access.
# If this is unexpected, please log in with password and setup Forgejo under another user.
當遇到 Permission Denied (publickey) 的錯誤時,印出更多資訊來除錯
ssh -vT git@codeberg.org