3.5 KiB
| eleventyNavigation | ||||||
|---|---|---|---|---|---|---|
|
It is recommended to use one key per client. It means 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 a shell (e.g.
git-bashon Windows orbashon Linux). -
Paste the text below, substituting in your Codeberg email address.
$ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"This creates a new ssh key, using the provided email as a label:
> Generating public/private rsa 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 a file in which to save the key (/c/Users/you/.ssh/id_rsa):[Press enter] -
Enter a passphrase if you want.
The private key part of your SSH key can be protected by a passphrase. This adds an additional layer of authentication which 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.
If you are using a passphrase-protected SSH key the use of a ssh agent is strongly encouraged for improved usability. You need to enter the passphrase only once during a session.
Add the SSH key to Codeberg
-
Copy the SSH key to your clipboard. Attention: Copy only the public part of the key not the private one. You can identify it by the
.pubextension. By default, you can find the public key in$HOME/.ssh/id_rsa.pub.On Linux you can use the
xclipcommand like this$ xclip -sel clip < ~/.ssh/id_rsa.pubOn Windows use a text editor (e.g. Notepad) or
clipon the command line$ type .ssh/id_rsa.pub | clip -
Navigate to your user settings
-
Go to the settings section SSH / GPG Keys and click on Add key.
- Give an appropriate name for the key.
- Paste your key string from the clipboard into content field.
Test the SSH connection
Do this simple test:
$ ssh -T git@codeberg.org
The output should look like this:
Hi there, You've successfully authenticated, but Gitea does not provide shell access.
If this is unexpected, please log in with password and setup Gitea 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.
Avoid re-typing the passphrase
Assuming you've created a secure key with passphrase, SSH will prompt you for your passphrase for every connection. Common desktop environments like OSX 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, this is then cached.