The Codeberg Documentation website is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
It bundles third-party font software licensed under a different license. Please look at the LICENSE file for details.
Changes to the original versions of the article as well as its individual authors can be looked up in this article's commit history
Codeberg and the Codeberg Logo are trademarks of Codeberg e.V.
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.
Open Terminal on Linux/macOS, or Git Bash on Windows.
Paste the text below:
ssh-keygen -t ed25519 -a 100
This will generate a new SSH key.
You can also add a comment to help you identify the client with -C "comment here"
.
> 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]
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.
Connect your security key and open a terminal
Paste the text below
ssh-keygen -t ed25519-sk
If you have set one on your key, you'll be prompted for your FIDO2 PIN. Enter it to continue
When you're prompted to "Enter a file in which to save the key", press Enter. This accepts the default file location.
You will be asked for a passphrase; enter one if you'd like, or leave the prompt empty.
Keep in mind that now, every time you wish to use Codeberg over SSH, you must have your security key plugged in and will be prompted to touch it to continue.
Copy the SSH key to your clipboard. You must only copy the public key not the private one. You can identify it by the .pub
suffix. By default, you can find the public key in $HOME/.ssh/id_ed25519.pub
.
On Linux you can use xclip
on the command line. You may need to install it from your package manager.
$ xclip -selection clipboard < ~/.ssh/id_ed25519.pub
On Windows you can use clip
.
$ clip < ~/.ssh/id_ed25519.pub
On macOS you can use pbcopy
.
$ pbcopy < ~/.ssh/id_ed25519.pub
These commands will copy the contents of id_ed25519.pub (your SSH public key) to your clipboard.
Alternatively you can locate the hidden .ssh folder, open the file in your favorite text editor, and copy it to your clipboard.
Navigate to your user settings
You can always access your SSH public keys from
https://codeberg.org/username.keys
, substituting in your Codeberg username.
Do this simple test:
$ ssh -T git@codeberg.org
The output should look like this:
Hi there, ____! You've successfully authenticated with the key named ____, but Forgejo does not provide shell access.
If this is unexpected, please log in with password and setup Forgejo under another user.
Note: All Codeberg users share a single Unix user named git
which is used to check out repositories. Depending on the key provided, permission is granted or denied. You can check out all repositories with your key which you have permission for. You can push code to all repositories where you have write access.
Anyone can add a random SSH key; but fortunately, Codeberg provides a mechanism to verify that the key belongs to you. Every keypair consists of a public and a private key that are connected to one another. Using this private key, you can sign the provided message. If the signed message is valid, Codeberg can confirm that the added key is yours.
/path_to_your_private_key
with the correct path of your private key.-----BEGIN SSH SIGNATURE-----
and ending with -----END SSH SIGNATURE-----
.SSH can also be used to sign commits as an alternative for GPG. You can read more about GPG commit signing here.
SSH commit signing is available in Git 2.34 or later. To update your version of Git, see the Git website.
git config --global gpg.format ssh
.git config --global user.signingKey <PATH TO PUBLIC SSH KEY>
, substituting <PATH TO PUBLIC SSH KEY>
with the path to the public key you'd like to use, for example ~/.ssh/id_ed25519.pub.git config --global commit.gpgSign true
.Assuming you've created a secure key with a passphrase, SSH will prompt you for your passphrase for every connection. Common desktop environments like macOS or GNOME will offer you to cache your passphrase via an SSH agent.
If you are working at the command line, you can alternatively do this directly:
$ eval $(ssh-agent)
$ ssh-add # enter your passphrase once, then it is cached.
Go to the directory where your repository is located:
cd /path/to/repository
Look at the existing remotes with git remote
:
git remote -v
It will look similar to this:
origin https://codeberg.org/knut/foobar.git (fetch)
origin https://codeberg.org/knut/foobar.git (push)
You might be using a different name than origin
for your repository. If you do, remember to use that different name in the following steps.
Run git remote set-url
command followed by the remote name and the remote’s URL:
git remote set-url <remote-name> <remote-url>
For example, to change the URL of origin
to git@codeberg.org:knut/foobar.git
you would type:
git remote set-url origin git@codeberg.org:knut/foobar.git
Your HTTPS URL used this format: https://codeberg.org/<user>/<repo>.git
The SSH URL uses this format: git@codeberg.org:<user>/<repo>.git
(optionally with ssh://
at the beginning like this: ssh://git@codeberg.org:<user>/<repo>.git
).
Alternatively, you can find the SSH URL by going to your repository page on Codeberg (for example, going to https://codeberg.org/knut/foobar
), clicking on SSH in the top right corner and copying the URL.
Verify that your change was successful:
git remote -v
The output should look like this:
origin ssh://git@codeberg.org:knut/foobar.git (fetch)
origin ssh://git@codeberg.org:knut/foobar.git (push)
Attribution
This guide is derived from GitHub Docs, used under CC-BY 4.0.
Hey there! 👋 Thank you for reading this article!
Is there something missing, or do you have an idea on how to improve the documentation? Do you want to write your own article?
You're invited to contribute to the Codeberg Documentation at its source code repository, for example, by adding a pull request or joining in on the discussion in the issue tracker.
For an introduction on contributing to Codeberg Documentation, please have a look at the Contributor FAQ.
© Codeberg Docs Contributors. See LICENSE