Generate, upload, and manage SSH keys
Last updated on
SSH (Secure Shell) lets you securely connect to and administer your virtual machines (VMs) on STACKIT. Instead of a password, SSH uses a key pair for authentication:
- The private key stays on your computer. Never share it with anyone.
- The public key is stored in your STACKIT user account. When you create a VM, STACKIT adds the public key to the VM, so you can log in with the matching private key.
SSH keys are stored per user account. They are independent of the customer account and are available in all projects you have access to.
This guide shows you how to:
- Generate an SSH key pair on your computer.
- Upload the public key to your STACKIT user account.
- List your SSH keys and compare them with your local keys.
- Manage your SSH keys in the STACKIT Portal.
Generate an SSH key pair
Section titled “Generate an SSH key pair”We recommend the key type Ed25519. It is secure, fast, and produces short keys. Use RSA with 4096 bits only if a tool you use doesn’t support Ed25519.
-
Open a terminal.
-
Generate a new key pair. Replace the comment with a label that helps you identify the key, for example your email address or the name of your computer:
Terminal window ssh-keygen -t ed25519 -C "your_email@example.com"If you need an RSA key instead, use
ssh-keygen -t rsa -b 4096 -C "your_email@example.com". -
When prompted for a file location, press Enter to accept the default path (
~/.ssh/id_ed25519), or enter a different path.Enter file in which to save the key (/home/you/.ssh/id_ed25519): -
Enter a secure passphrase and repeat it. The passphrase encrypts your private key on disk, so it can’t be used if somebody gets hold of the file.
Enter passphrase (empty for no passphrase):Enter same passphrase again: -
Display the public key:
Terminal window cat ~/.ssh/id_ed25519.pubThe output is a single line similar to the following. You need this line when you upload the key to STACKIT.
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIK0wmN/Cr3JXqmLW7u+g9pTh+wyqDHpSQEIQczXkVx9q your_email@example.com
Windows 10 (version 1809 and later) and Windows 11 include the OpenSSH client, so you don’t need to install additional software.
-
Open PowerShell or Windows Terminal.
-
Generate a new key pair. Replace the comment with a label that helps you identify the key, for example your email address or the name of your computer:
Terminal window ssh-keygen -t ed25519 -C "your_email@example.com" -
When prompted for a file location, press Enter to accept the default path (
C:\Users\<username>\.ssh\id_ed25519), or enter a different path. -
Enter a secure passphrase and repeat it. The passphrase encrypts your private key on disk, so it can’t be used if somebody gets hold of the file.
-
Display the public key:
Terminal window Get-Content $env:USERPROFILE\.ssh\id_ed25519.pubThe output is a single line that starts with
ssh-ed25519. You need this line when you upload the key to STACKIT.
Optional: Add the key to the SSH agent
Section titled “Optional: Add the key to the SSH agent”The SSH agent keeps your unlocked private key in memory, so you don’t need to enter the passphrase every time you connect.
-
Start the SSH agent in the background:
Terminal window eval "$(ssh-agent -s)" -
Add your private key to the agent and enter your passphrase:
Terminal window ssh-add ~/.ssh/id_ed25519 -
macOS only: To load the key automatically and store the passphrase in your keychain, add the following to the file
~/.ssh/config. Create the file if it doesn’t exist.Host *AddKeysToAgent yesUseKeychain yesIdentityFile ~/.ssh/id_ed25519Then add the key once with
ssh-add --apple-use-keychain ~/.ssh/id_ed25519.
-
Open PowerShell as administrator and start the SSH agent service. Set it to start automatically:
Terminal window Get-Service ssh-agent | Set-Service -StartupType AutomaticStart-Service ssh-agent -
In a regular PowerShell session, add your private key to the agent and enter your passphrase:
Terminal window ssh-add $env:USERPROFILE\.ssh\id_ed25519
Upload the public key to STACKIT
Section titled “Upload the public key to STACKIT”Prerequisites
Section titled “Prerequisites”- You have generated an SSH key pair.
- For the CLI: You have installed and authenticated the STACKIT CLI.
- For the API: You have a valid STACKIT access token and set it in the
STACKIT_ACCESS_TOKENenvironment variable. With the STACKIT CLI, you get a short-lived token for your user account, for exampleexport STACKIT_ACCESS_TOKEN=$(stackit auth get-access-token)(Linux and macOS) or$env:STACKIT_ACCESS_TOKEN = stackit auth get-access-token(PowerShell).
Procedure
Section titled “Procedure”-
Copy your public key to the clipboard:
- macOS:
pbcopy < ~/.ssh/id_ed25519.pub - Linux:
xclip -selection clipboard < ~/.ssh/id_ed25519.pub(orwl-copy < ~/.ssh/id_ed25519.pubon Wayland) - Windows (PowerShell):
Get-Content $env:USERPROFILE\.ssh\id_ed25519.pub | Set-Clipboard
Alternatively, display the key with
cat(orGet-Contenton Windows) and copy the complete line manually. - macOS:
-
Open the SSH key settings in the STACKIT Portal.
-
Select + Create SSH key.
-
In the field Key name, enter a name that helps you identify the key, for example
laptop-work. -
In the field Please enter a key, paste your public key. Make sure you paste the complete line, starting with the key type, for example
ssh-ed25519. -
Select Create.
Upload your public key directly from the file. The @ prefix tells the CLI to read the value from the file:
stackit key-pair create --name laptop-work --public-key @$HOME/.ssh/id_ed25519.pubYou can also add labels to the key:
stackit key-pair create --name laptop-work --public-key @$HOME/.ssh/id_ed25519.pub --labels team=opsThe CLI doesn’t expand ~, so use $HOME in the path. On Windows (PowerShell), use @$env:USERPROFILE\.ssh\id_ed25519.pub.
For all options, see the CLI reference for stackit key-pair.
Send a POST request to the keypairs endpoint of the IaaS API:
curl -X POST "https://iaas.api.stackit.cloud/v2/keypairs" \ -H "Authorization: Bearer $STACKIT_ACCESS_TOKEN" \ -H "Content-Type: application/json" \ -d '{ "name": "laptop-work", "publicKey": "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIK0wmN/Cr3JXqmLW7u+g9pTh+wyqDHpSQEIQczXkVx9q your_email@example.com" }'For details, see the API reference for Keypairs.
After the upload, the key is shown in your list of SSH keys. STACKIT automatically calculates the fingerprint of the key. You can now select the key as initial credential when you create a VM.
List SSH keys
Section titled “List SSH keys”- Open the SSH key settings in the STACKIT Portal.
The page lists all SSH keys of the user you’re currently logged in with. For each key, the name, the fingerprint and the creation date are displayed.
stackit key-pair listcurl "https://iaas.api.stackit.cloud/v2/keypairs" \ -H "Authorization: Bearer $STACKIT_ACCESS_TOKEN"To check which local key belongs to a stored key, compare the fingerprint shown in the portal or the CLI with the MD5 fingerprint of your local key. STACKIT displays MD5 fingerprints, while ssh-keygen uses SHA256 by default, so add -E md5:
ssh-keygen -E md5 -lf ~/.ssh/id_ed25519.pubManage SSH keys
Section titled “Manage SSH keys”- Open the SSH key settings in the STACKIT Portal.
- Select the context menu of the SSH key you want to change by clicking on the three dots at the end of the row.
- Select the action you want to perform. You can perform the actions Delete, Rename, and Set as Default.
Set as default
Section titled “Set as default”This action sets your selected SSH key as the default key. When you create a VM, this key is pre-selected as the initial credential. You can still choose a different SSH key during the VM creation process.
Rename
Section titled “Rename”You can rename an SSH key. This action doesn’t change the key itself. Each key must have a unique name.
Delete
Section titled “Delete”This action deletes an SSH key from your user account. After deletion, you can’t select this key when you create VMs. Existing VMs where the key was already added as initial credential aren’t affected. To revoke access to an existing VM, remove the key from the ~/.ssh/authorized_keys file of the user you use to connect to the VM.
You can also delete a key with the CLI (stackit key-pair delete <name>) or the API (DELETE https://iaas.api.stackit.cloud/v2/keypairs/<name>).
Next steps
Section titled “Next steps”- To connect to a VM, use
ssh -i ~/.ssh/id_ed25519 <username>@<ip-address>. The username depends on the operating system image of the VM, see Username for SSH access.