SSH
- Tier: Free, Premium, Ultimate
- Offering: GitLab.com, GitLab Self-Managed, GitLab Dedicated
This executor is in maintenance mode. It receives critical security updates but no new features are planned. For new projects, consider using one of the actively developed executors.
The SSH executor is included for completeness, but it’s among the least supported executors. GitLab Runner connects to an external server and runs builds there over SSH. While some organizations use this executor successfully, it’s generally better to use a different executor type.
The SSH executor supports only scripts generated in Bash and the caching feature is not supported.
This executor allows you to execute builds on a remote machine by executing commands over SSH.
Ensure you meet common prerequisites on any remote systems where GitLab Runner uses the SSH executor.
Use the SSH executor
To use the SSH executor, specify executor = "ssh" in the
[runners.ssh] section. For example:
[[runners]]
executor = "ssh"
[runners.ssh]
host = "example.com"
port = "22"
user = "root"
password = "password"
identity_file = "/path/to/identity/file"You can use password or identity_file or both to authenticate against the
server. GitLab Runner doesn’t implicitly read identity_file from
/home/user/.ssh/id_(rsa|ecdsa|ed25519). The identity_file needs to be
explicitly specified. DSA keys (id_dsa) and SSH servers that offer only an
ssh-dss host key are no longer supported.
The project’s source is checked out to:
~/builds/<short-token>/<concurrent-id>/<namespace>/<project-name>.
Where:
<short-token>is a shortened version of the runner’s token (first 8 letters)<concurrent-id>is the index of the runner from the list of all runners that run a build for the same project concurrently (accessible through theCI_CONCURRENT_PROJECT_IDpre-defined variable).<namespace>is the namespace where the project is stored on GitLab<project-name>is the name of the project as it is stored on GitLab
To overwrite the ~/builds directory, specify the builds_dir options under
[[runners]] section in config.toml.
If you want to upload job artifacts, install gitlab-runner on the host you are
connecting to through SSH.
Configure strict host key checking
SSH StrictHostKeyChecking is enabled by default.
GitLab Runner checks the host key of the remote server against a known_hosts file.
By default, GitLab Runner uses .ssh/known_hosts in the home directory of the user that runs GitLab Runner.
To use a different file, set known_hosts_file in the [runners.ssh] section:
[runners.ssh]
host = "example.com"
port = "22"
user = "root"
identity_file = "/path/to/identity/file"
known_hosts_file = "/path/to/known_hosts"Use an absolute path for known_hosts_file. GitLab Runner does not expand ~.
If the job fails, check the error message:
knownhosts: key is unknown: The host key is not in theknown_hostsfile. Add the host key.knownhosts: key mismatch: Theknown_hostsfile has an entry for the host, but none of its keys match the key that the server presented. The host key might have changed, or the file might not contain every key type that the server offers. Verify the fingerprints, then replace the host key.getting host key callback: open <path>: no such file or directory: Theknown_hostsfile does not exist. Add the host key, which creates the file.
Add the host key of the remote server
To add the host key of the remote server to the known_hosts file:
On the GitLab Runner host, as the user that runs GitLab Runner, scan the remote server. Replace
example.comand22with thehostandportvalues from[runners.ssh]:ssh-keyscan -p 22 example.com > host_keys.txt ssh-keygen -lf host_keys.txtDo not limit the scan with
-t. The file must contain every host key type that the server offers.On the remote server, run
ssh-keygen -lf <public_host_key_file>for each public host key. These files are usually in/etc/ssh/and namedssh_host_*_key.pub. Confirm that every fingerprint from the previous step appears in this output. If one does not, do not continue.Add the keys to the
known_hostsfile:mkdir -p ~/.ssh cat host_keys.txt >> ~/.ssh/known_hostsThe commands create the
.sshdirectory and theknown_hostsfile if they do not exist.If you set
known_hosts_file, replace~/.ssh/known_hostswith that path and make sure its parent directory exists.
Replace a changed host key
To replace the host key of the remote server after it changes:
On the GitLab Runner host, as the user that runs GitLab Runner, remove the old entry. Replace
<host>with thehostvalue from[runners.ssh]. For a port other than22, use[<host>]:<port>.ssh-keygen -R <host>If you set
known_hosts_file, add-f <known_hosts_file>.Add the new host key by repeating the steps to add the host key of the remote server.
Disable strict host key checking
When you disable strict host key checking, GitLab Runner does not verify the identity of the
remote server. This setting makes the connection vulnerable to man-in-the-middle attacks.
Add the host key to the known_hosts file instead.
To disable strict host key checking, set disable_strict_host_key_checking to true in the [runners.ssh] section.
The default value is false.