In comparison to using HTTPS, SSH keys provide a safer and passwordless way to authenticate with Codeberg. It is recommended to use one key per client. This means that if you access your Codeberg repository from your home PC, your laptop and your office PC you should generate separate keys for each machine.
Generating an SSH key pair
-
Open Terminal on Linux/macOS, or Git Bash on Windows.
-
Paste the text below:
ssh-keygen -t ed25519 -a 100This will generate a new SSH key. You can also add a comment to help you identify the client with
-C "comment here".The program may also ask for a name and email address to associate with the key. While it is recommended to fill in something identifiable here, if you don't wish to, it may safely be left blank. These fields are for organizational purposes.
> Generating public/private ed25519 key pair. -
When you're prompted to "Enter a file in which to save the key", press Enter. This accepts the default file location:
> Enter file in which to save the key (/home/knut/.ssh/id_ed25519): [Press enter]If you see that
/home/knut/.ssh/id_ed25519 already exists, follow these steps:-
When prompted to overwrite the existing file, type n to choose not to overwrite.
-
Afterward, re-run the same command. This time, enter a new filepath when prompted (e.g.,
/home/knut/.ssh/id_ed25519_codeberg) to avoid overwriting the existing key.
WarningNote that if you choose to create a key with a new name, you will have to update your
configfile as explained below. -
-
You will be asked for a passphrase; enter one if you'd like, or leave the prompt empty.
Your private key can be protected by a passphrase. This adds a layer of authentication that increases security. Be aware that this will only be helpful for certain attack scenarios and does not offer 100% protection. It is recommended to keep your private key safe and - well - private.