Azure DevOps SSH-RSA Setup and Configuration

Author

Reads 561

Men Working on a Computer
Credit: pexels.com, Men Working on a Computer

Azure DevOps SSH-RSA setup is a crucial step in securing your deployment process. SSH-RSA is a key pair that allows secure communication between your local machine and Azure DevOps.

To generate a new SSH-RSA key pair, you can use the ssh-keygen command in your terminal. This command will create a new pair of keys, a private key and a public key.

The private key should be kept secure and not shared with anyone, while the public key can be shared freely. In Azure DevOps, you can add the public key to your user account or a service connection to enable SSH access.

Setting Up SSH Keys

To use SSH key authentication, you first need to generate public/private key pairs for your client. The only SSH key type supported by Azure DevOps is RSA.

You can use ssh-keygen.exe to generate key files, specifying the RSA algorithm. If you don't specify an algorithm, Ed25519 is used, but for Azure DevOps, you should use RSA-SHA2-256 or RSA-SHA2-512.

Credit: youtube.com, How To Setup SSH Connection To Azure DevOps

The output from the command will display the following output, where username is your username: You can press Enter to accept the default, or specify a path and/or filename where you would like your keys to be generated.

At this point, you're prompted to use a passphrase to encrypt your private key files. The passphrase can be empty, but it's not recommended, as it provides two-factor authentication.

The private key files are the equivalent of a password and should be protected the same way. Never share the contents of your private key.

Here's a summary of the steps to generate SSH keys:

  • Run ssh-keygen.exe with the RSA algorithm
  • Specify a path and/or filename for the key files
  • Use a passphrase to encrypt the private key files (optional)

Note: The private key files should be kept secure and not shared with anyone.

Connecting to Azure DevOps

Connecting to Azure DevOps is a crucial step in using SSH-RSA. You'll first need to create an SSH host in Azure.

To connect to your SSH host, click on the indicator on the bottom-left corner of the Status bar. This will bring up a list of Remote extension commands.

Credit: youtube.com, Using SSH to authenticate Git in Azure DevOps

Choose the Connect to Host... command in the Remote-SSH section and enter connection information for your VM in the format user@hostname. The user is the username you set when adding the SSH public key to your VM.

Before connecting in Remote-SSH, you can verify you're able to connect to your VM via a command prompt using ssh user@hostname. If you run into an error, you may need to delete NRMS-Rule-106 from the Networking tab of your VM.

Once connected, you can interact with files and open folders on the remote machine. You can also use the bash shell to browse the file system on the VM.

To configure your SSH connections, open the Remote explorer and select SSH Targets. Here, you can save the hosts you connect to the most and access them from here instead of entering the user and hostname.

Preparing for Git Repository

To prepare for a Git repository, you'll need to create a private key file, which you'll copy into Azure Pipelines. Copy the private key file created in the previous step, id_rsa, into Azure Pipelines -> Library -> Secure files, and rename it for easier use later on.

Credit: youtube.com, Azure DevOps SSH Git Clone

You'll also need to add the public key to your Azure DevOps settings. Under user settings, go to SSH public keys and select Add, giving a name and adding the contents of the file created id_rsa.pub. This can be renamed for easier use as well.

Here's a list of variables you'll need to create for your pipeline:

  • SSH public key variable: terraform-git-ssh-pub
  • Known hosts variable: git_ssh_known_hosts
  • Optional: passphrase variable: git_ssh_pass

These variables can be stored as secrets in Azure Key Vault instead, accessed using the Azure Key Vault task in your pipeline.

Clone Git Repository

To clone a Git repository, you'll need to use the SSH clone URL from the web portal. This URL is in the format dev.azure.com/{your organization}/{your project}.

The first step is to copy the SSH clone URL from the web portal.

You can then run the command `git clone` from the command prompt, followed by the SSH clone URL. For example, `git clone [email protected]:v3/fabrikam-fiber/FabrikamFiber/FabrikamFiber`.

If you're using an SSH Agent, you won't be prompted to enter your passphrase. However, if you aren't using an SSH Agent, you'll be prompted to enter your passphrase.

Credit: youtube.com, Creating and Cloning a Git Repository

Here are the steps to clone a Git repository:

  1. Copy the SSH clone URL from the web portal.
  2. Run `git clone` from the command prompt, followed by the SSH clone URL.

Note that if you're prompted to enter your passphrase, you can read the section on adding the public key to Azure DevOps to resolve the issue.

Prepare

To prepare for a Git repository, you'll need to install an OpenSSH compatible SSH client, as PuTTY is not supported.

You'll also need to install Visual Studio Code, which is a popular code editor.

Having an Azure subscription is also required, so if you don't already have one, create a free account before you begin.

To generate a key pair, you can use the ssh-keygen command in a PowerShell console. This will create a private key and a public key under the %UserProfile%/.ssh directory.

If you used a passphrase when generating the key pair, make a note of it as you'll need it later.

You can also use the ssh-keyscan command to recover your "Known Hosts Entry" by running ssh-keyscan github.com in GitBash.

Troubleshooting and Best Practices

Credit: youtube.com, Secure Your Azure DevOps Organization | Best Practices for Azure DevOps Security

Troubleshooting Azure DevOps SSH issues can be frustrating, but there are some key things to keep in mind. If you're seeing multiple different problems, you can try verifying the fingerprint of the public key uploaded with the one displayed in your profile through the ssh-keygen command.

You might also need to update the origin remote in Git to change over from an HTTPS to SSH URL. This is especially important during the transition period from MD5 to SHA-256 hashes. As of August/September 2024, this is a good time to get ahead of the curve.

Azure DevOps blindly accepts the first key that the client provides during authentication, so make sure you're using the correct key for the requested repository. If not, the request will fail with an error.

Questions and Troubleshooting

If you're experiencing issues with SSH connections, you may see warning messages due to multiple different problems.

Azure DevOps uses SHA-256 hashes as of August/September 2024, so you may need to choose the correct function during the transition period.

Credit: youtube.com, Application Troubleshooting Best Practices

To verify the fingerprint of your public key, run the ssh-keygen command against your public key using the command line, changing the path and filename if necessary.

You can update the origin remote in Git by changing from an HTTPS to SSH URL, then run the command to update the remote.

If you're using a key stored in a different location than the default, you'll need to specify the path to the key in your SSH config file.

Azure DevOps blindly accepts the first key provided during authentication, so if that key is invalid, the request will fail with an error message.

To resolve ssh-rsa related warnings, remove any lines in your SSH config file that downgrade security settings and ensure rsa-sha2-256 and/or rsa-sha2-512 are allowed.

Some Linux distributions, such as Fedora Linux, have crypto policies that require stronger SSH signature algorithms than Azure DevOps supports, which can cause connection problems.

Best Practices

To avoid access issues, your public key should be added to the repository or organization.

Credit: youtube.com, Troubleshooting and Best Practices

Passing your public key as plain text to the task configuration is not recommended. Instead, set a secret variable in your pipeline for the contents of your mykey.pub file.

Use the Secure File library in Azure Pipelines for the secret part of your key.

Your task should be created using a well-configured Install SSH Key task, such as the example provided.

For GitHub, follow the guide to add your public key, and for Azure DevOps Services, use the instructions to add the public key.

Using Multiple Key Sets for Organizations

To use different SSH keys for different organizations on Azure DevOps, you need to modify your SSH configuration to provide distinct keys for each. This is because all Azure DevOps URLs share the same hostname, making it impossible for SSH to distinguish between them by default.

You can create separate Host sections in your SSH configuration file using host aliases. This allows you to provide unique keys for each organization. For example, you can use host aliases like devops_fabrikam and devops_contoso.

After modifying your SSH configuration, replace the hostname in the existing remotes with the host aliases. For instance, [email protected]:v3/Fabrikam/Project1/fab_repo would become git@devops_fabrikam:v3/Fabrikam/Project1/fab_repo. This way, you can use different SSH keys for different organizations on Azure DevOps.

Two Answers

Credit: youtube.com, Day 2: Session 1: Best practices and troubleshooting

As you navigate the world of SSH and Azure DevOps, you may encounter some common issues that can be frustrating to resolve. But don't worry, I've got you covered. Specifically, my understanding is that there is a distinction between key types and signature types.

The "ssh-rsa" key type is used by the "ssh-rsa", "rsa-sha2-256" and "rsa-sha2-512" signature types. This is important to know because the ssh-rsa signature type is being deprecated due to security concerns surrounding SHA-1.

If you're experiencing issues with ssh-rsa, you may need to upgrade your OpenSSH version. This is because some Linux distributions, such as Fedora Linux, have crypto policies that require stronger SSH signature algorithms than Azure DevOps supports.

You can verify the fingerprint of the public key uploaded with the one displayed in your profile through the following ssh-keygen command run against your public key using the command line. This is a useful check if you have connection problems or have concerns about incorrectly pasting in the public key into the Key Data field when adding the key to Azure DevOps.

Credit: youtube.com, Troubleshooting Basics

Here are some key points to keep in mind:

  • The ssh-rsa signature type is being deprecated starting April 2024.
  • The ssh-rsa key type is still fine as long as the key length is sufficient.
  • Upgrading your OpenSSH version may resolve issues with ssh-rsa.
  • Crypto policies in some Linux distributions, such as Fedora Linux, may require stronger SSH signature algorithms than Azure DevOps supports.

Remember, it's always a good idea to verify the fingerprint of your public key to ensure everything is configured correctly. And if you're still experiencing issues, don't hesitate to reach out for help.

Judith Lang

Senior Assigning Editor

Judith Lang is a seasoned Assigning Editor with a passion for curating engaging content for readers. With a keen eye for detail, she has successfully managed a wide range of article categories, from technology and software to education and career development. Judith's expertise lies in assigning and editing articles that cater to the needs of modern professionals, providing them with valuable insights and knowledge to stay ahead in their fields.

Love What You Read? Stay Updated!

Join our community for insights, tips, and more.