Reviewed on 08 October 2024 • Published on 08 October 2024
In cloud environments, managing SSH keys across multiple Instances is key to keeping your infrastructure secure and easy to access.
Sometimes, you need to ensure that a specific SSH key grants access to only one Instance and does not automatically apply to others.
This can simplify key management and improve security, especially when you are running many Instances
# - Be sure to replace all spaces with underscores
# - $> sed 's/ /_/g' ~/.ssh/id_rsa.pub
# -- Add the keys to '/root/.ssh/Instance_keys' which will be imported
#
# And recreate your 'authorized_keys' file with the new keys:
# -- Run 'scw-fetch-ssh-keys --upgrade'
[...]
This file lists all the SSH public keys allowed to access the Instance. Our goal is to add an Instance-specific SSH key that will not be automatically applied to other Instances.
Click Instances in the Compute section of the side menu. The Instances overview displays.
Click the Instance you want to add a specific key to.
Navigate to the section where you can add tags to the Instance on the Instances overview page.
Add the public SSH key tag by writing in the Tags form. You can add multiple keys by creating separate AUTHORIZED_KEY tags for each SSH key.
The format for creating SSH key tags is:
Remember to replace any spaces with underscores (_) in the SSH public key string when entering it as a tag. Your actual SSH public key remains unchanged.
Run the following command on your Instance to update the list of authorized public keys:
scw-fetch-ssh-keys --upgrade
Verify the SSH key on the Instance by typing the following command:
cat /root/.ssh/authorized_keys
The Instance-specific key has been added to the /root/.ssh/authorized_keys file on the Instance alongside with your account-wide configured keys.
The specific tag public key will not propagate to other Instances in your infrastructure.
Tip
Another option to update the SSH keys of your Instances is to reboot them.
You now have configured an Instance-specific SSH key through the Scaleway console.
One of the main advantages of using tags for SSH keys is that they will not apply to other Instances, even after updates or reboots.
This ensures that only the designated Instance can be accessed with the specified SSH key.