@@ -128,7 +128,7 @@ We'll use this variable in the `.gitlab-ci.yml` later, to easily connect to our
...
@@ -128,7 +128,7 @@ We'll use this variable in the `.gitlab-ci.yml` later, to easily connect to our
![variables page](img/variables_page.png)
![variables page](img/variables_page.png)
We also need to add the public key to **Project** > **Settings** > **Repository** as a [Deploy Key](../../../ssh/README.md#deploy-keys), which gives us the ability to access our repository from the server through [SSH protocol](../../../gitlab-basics/command-line-commands.md#start-working-on-your-project).
We also need to add the public key to **Project** > **Settings** > **Repository** as a [Deploy Key](../../../user/project/deploy_keys/index.md), which gives us the ability to access our repository from the server through [SSH protocol](../../../gitlab-basics/command-line-commands.md#start-working-on-your-project).
Git is a distributed version control system, which means you can work locally.
Git is a distributed version control system, which means you can work locally,
In addition, you can also share or "push" your changes to other servers.
then share or "push" your changes to a server. In this case, the server is GitLab.
GitLab supports secure communication between Git and its servers using SSH keys.
The SSH protocol provides this security and allows you to authenticate to the
GitLab uses the SSH protocol to securely communicate with Git.
GitLab remote server without supplying your username or password each time.
When you use SSH keys to authenticate to the GitLab remote server,
you don't need to supply your username and password each time.
This page can help you configure secure SSH keys which you can use to help secure
connections to GitLab repositories.
- If you need information on creating SSH keys, start with our [options for SSH keys](#supported-ssh-key-types).
- If you have SSH keys dedicated for your GitLab account, you may be interested in [Working with non-default SSH key pair paths](#working-with-non-default-ssh-key-pair-paths).
- If you already have an SSH key pair, you can go to how you can [add an SSH key to your GitLab account](#add-an-ssh-key-to-your-gitlab-account).
## Prerequisites
## Prerequisites
...
@@ -31,7 +24,7 @@ To use SSH to communicate with GitLab, you need:
...
@@ -31,7 +24,7 @@ To use SSH to communicate with GitLab, you need:
To view the version of SSH installed on your system, run `ssh -V`.
To view the version of SSH installed on your system, run `ssh -V`.
GitLab does [not support installation on Microsoft Windows](../install/requirements.md#microsoft-windows),
GitLab does [not support installation on Microsoft Windows](../install/requirements.md#microsoft-windows),
but you can set up SSH keys on the Windows [client](#options-for-microsoft-windows).
but you can set up SSH keys on the Windows [client](#use-ssh-on-microsoft-windows).
## Supported SSH key types
## Supported SSH key types
...
@@ -104,10 +97,10 @@ If you do not have an existing SSH key pair, generate a new one.
...
@@ -104,10 +97,10 @@ If you do not have an existing SSH key pair, generate a new one.
Enter file in which to save the key (/home/user/.ssh/id_ed25519):
Enter file in which to save the key (/home/user/.ssh/id_ed25519):
```
```
1. Accept the suggested filename and directory, unless you are generating a [deploy key](#deploy-keys)
1. Accept the suggested filename and directory, unless you are generating a [deploy key](../user/project/deploy_keys/index.md)
or want to save in a specific directory where you store other keys.
or want to save in a specific directory where you store other keys.
You can also dedicate the SSH key pair to a [specific host](#working-with-non-default-ssh-key-pair-paths).
You can also dedicate the SSH key pair to a [specific host](#configure-ssh-to-point-to-a-different-directory).
1. Specify a [passphrase](https://www.ssh.com/ssh/passphrase/):
1. Specify a [passphrase](https://www.ssh.com/ssh/passphrase/):
...
@@ -122,11 +115,43 @@ A public and private key are generated.
...
@@ -122,11 +115,43 @@ A public and private key are generated.
[Add the public SSH key to your GitLab account](#add-an-ssh-key-to-your-gitlab-account) and keep
[Add the public SSH key to your GitLab account](#add-an-ssh-key-to-your-gitlab-account) and keep
the private key secure.
the private key secure.
### Configure SSH to point to a different directory
If you did not save your SSH key pair in the default directory,
configure your SSH client to point to the directory where the private key is stored.
1. Open a terminal and run this command:
```shell
eval$(ssh-agent -s)
ssh-add <directory to private SSH key>
```
1. Save these settings in the `~/.ssh/config` file. For example:
```conf
# GitLab.com
Hostgitlab.com
PreferredAuthenticationspublickey
IdentityFile ~/.ssh/gitlab_com_rsa
# Private GitLab instance
Hostgitlab.company.com
PreferredAuthenticationspublickey
IdentityFile ~/.ssh/example_com_rsa
```
For more information on these settings, see the [`man ssh_config` (SSH config manual)](https://man.openbsd.org/ssh_config) page.
Public SSH keys must be unique to GitLab because they bind to your account.
Your SSH key is the only identifier you have when you push code with SSH.
It must uniquely map to a single user.
### Update your SSH key passphrase
### Update your SSH key passphrase
You can update the passphrase for your SSH key.
You can update the passphrase for your SSH key.
1. Open a terminal and type this command:
1. Open a terminal and run this command:
```shell
```shell
ssh-keygen -p-f /path/to/ssh_key
ssh-keygen -p-f /path/to/ssh_key
...
@@ -140,7 +165,7 @@ If your version of OpenSSH is between 6.5 and 7.8,
...
@@ -140,7 +165,7 @@ If your version of OpenSSH is between 6.5 and 7.8,
you can save your private RSA SSH keys in a more secure
you can save your private RSA SSH keys in a more secure
OpenSSH format.
OpenSSH format.
1. Open a terminal and type this command:
1. Open a terminal and run this command:
```shell
```shell
ssh-keygen -o-f ~/.ssh/id_rsa
ssh-keygen -o-f ~/.ssh/id_rsa
...
@@ -155,11 +180,10 @@ OpenSSH format.
...
@@ -155,11 +180,10 @@ OpenSSH format.
## Add an SSH key to your GitLab account
## Add an SSH key to your GitLab account
Now you can copy the SSH key you created to your GitLab account.
To use SSH with GitLab, copy your public key to your GitLab account.
1. Copy your **public** SSH key to a location that saves information in text format.
1. Copy the contents of your public key file. You can do this manually or use a script.
The following options saves information for ED25519 keys to the clipboard
For example, to copy an ED25519 key to the clipboard:
for the noted operating system:
**macOS:**
**macOS:**
...
@@ -167,7 +191,7 @@ Now you can copy the SSH key you created to your GitLab account.
...
@@ -167,7 +191,7 @@ Now you can copy the SSH key you created to your GitLab account.
pbcopy < ~/.ssh/id_ed25519.pub
pbcopy < ~/.ssh/id_ed25519.pub
```
```
**Linux (requires the `xclip` package):**
**Linux** (requires the `xclip` package):
```shell
```shell
xclip -sel clip < ~/.ssh/id_ed25519.pub
xclip -sel clip < ~/.ssh/id_ed25519.pub
...
@@ -179,128 +203,83 @@ Now you can copy the SSH key you created to your GitLab account.
...
@@ -179,128 +203,83 @@ Now you can copy the SSH key you created to your GitLab account.
cat ~/.ssh/id_ed25519.pub | clip
cat ~/.ssh/id_ed25519.pub | clip
```
```
If you're using an RSA key, substitute accordingly.
Replace `id_ed25519.pub` with your filename. For example, use `id_rsa.pub` for RSA.
1. Navigate to `https://gitlab.com` or your local GitLab instance URL and sign in.
1. Sign in to GitLab.
1. In the top-right corner, select your avatar.
1. In the top right corner, select your avatar.
1. Select **Edit profile**.
1. Select **Settings**.
1. In the left sidebar, select **SSH Keys**.
1. From the left sidebar, select **SSH Keys**.
1. Paste the public key that you copied into the **Key** text box.
1. In the **Key** box, paste the contents of your public key.
1. Make sure your key includes a descriptive name in the **Title** text box, such as _Work Laptop_ or
If you manually copied the key, make sure you copy the entire key,
which starts with `ssh-ed25519` or `ssh-rsa`, and may end with a comment.
1. In the **Title** text box, type a description, like _Work Laptop_ or
_Home Workstation_.
_Home Workstation_.
1. Include an (optional) expiry date for the key under "Expires at" section. (Introduced in [GitLab 12.9](https://gitlab.com/gitlab-org/gitlab/-/issues/36243).)
1. Optional. In the **Expires at** box, select an expiration date. (Introduced in [GitLab 12.9](https://gitlab.com/gitlab-org/gitlab/-/issues/36243).)
1. Click the **Add key** button.
The expiration date is informational only, and does not prevent you from using
the key. However, administrators can view expiration dates and
SSH keys that have "expired" using this procedure are valid in GitLab workflows.
use them for guidance when [deleting keys](../user/admin_area/credentials_inventory.md#delete-a-users-ssh-key).
As the GitLab-configured expiration date is not included in the SSH key itself,
1. Select **Add key**.
you can still export public SSH keys as needed.
NOTE:
If you manually copied your public SSH key make sure you copied the entire
key starting with `ssh-ed25519` (or `ssh-rsa`) and ending with your email address.
## Two-factor Authentication (2FA)
## Verify that you can connect
You can set up two-factor authentication (2FA) for
Verify that your SSH key was added correctly.
[Git over SSH](../security/two_factor_authentication.md#two-factor-authentication-2fa-for-git-over-ssh-operations).
## Testing that everything is set up correctly
To test whether your SSH key was added correctly, run the following
1. For GitLab.com, to ensure you're connecting to the correct server, confirm the
command in your terminal (replace `gitlab.com` with the domain of
Private and public keys contain sensitive data. Ensure the permissions
on the files make them readable to you but not accessible to others.
Read the [documentation on deploy keys](../user/project/deploy_keys/index.md).
## Configure two-factor authentication (2FA)
## Applications
You can set up two-factor authentication (2FA) for
[Git over SSH](../security/two_factor_authentication.md#two-factor-authentication-2fa-for-git-over-ssh-operations).
### Eclipse
## Use EGit on Eclipse
If you are using [EGit](https://www.eclipse.org/egit/), you can [add your SSH key to Eclipse](https://wiki.eclipse.org/EGit/User_Guide#Eclipse_SSH_Configuration).
If you are using [EGit](https://www.eclipse.org/egit/), you can [add your SSH key to Eclipse](https://wiki.eclipse.org/EGit/User_Guide#Eclipse_SSH_Configuration).
## SSH on the GitLab server
## Use SSH on Microsoft Windows
GitLab integrates with the system-installed SSH daemon, designating a user
If you're running Windows 10, you can use the [Windows Subsystem for Linux (WSL)](https://docs.microsoft.com/en-us/windows/wsl/install-win10)
with [WSL 2](https://docs.microsoft.com/en-us/windows/wsl/install-win10#update-to-wsl-2).
You can use WSL to install Linux distributions, which include the Git and SSH clients.
For other versions of Windows, you can install the Git and SSH clients by using
GitLab integrates with the system-installed SSH daemon and designates a user
(typically named `git`) through which all access requests are handled. Users
(typically named `git`) through which all access requests are handled. Users
connecting to the GitLab server over SSH are identified by their SSH key instead
who connect to the GitLab server over SSH are identified by their SSH key instead
of their username.
of their username.
SSH *client* operations performed on the GitLab server are executed as this
SSH *client* operations performed on the GitLab server are executed as this
user. Although it is possible to modify the SSH configuration for this user to,
user. You can modify this SSH configuration. For example, you can specify
e.g., provide a private SSH key to authenticate these requests by, this practice
a private SSH key for this user to use for authentication requests. However, this practice
is **not supported** and is strongly discouraged as it presents significant
is **not supported** and is strongly discouraged as it presents significant
security risks.
security risks.
The GitLab check process includes a check for this condition, and directs you
GitLab checks for this condition, and directs you
to this section if your server is configured like this, for example:
to this section if your server is configured this way. For example:
```shell
```shell
$ gitlab-rake gitlab:check
$ gitlab-rake gitlab:check
...
@@ -383,30 +363,16 @@ Git user has default SSH configuration? ... no
...
@@ -383,30 +363,16 @@ Git user has default SSH configuration? ... no
Please fix the error above and rerun the checks.
Please fix the error above and rerun the checks.
```
```
Remove the custom configuration as soon as you're able to. These customizations
Remove the custom configuration as soon as you can. These customizations
are *explicitly not supported* and may stop working at any time.
are **explicitly not supported** and may stop working at any time.
### Options for Microsoft Windows
If you're running Windows 10, the [Windows Subsystem for Linux (WSL)](https://docs.microsoft.com/en-us/windows/wsl/install-win10), and its latest [WSL 2](https://docs.microsoft.com/en-us/windows/wsl/install-win10#update-to-wsl-2) version,
support the installation of different Linux distributions, which include the Git and SSH clients.
For current versions of Windows, you can also install the Git and SSH clients with