Configure multiple SSH keys
This topic explains how to configure SSH keys to manage multiple Alibaba Cloud DevOps accounts on one computer.
Background
An SSH key is an authorization credential for cloning code from a code repository. It is unique across the platform and represents a specific account. Each Alibaba Cloud DevOps account requires a different SSH key to identify users, map their permissions, and create audit trails.
Prerequisites
To access Codeup over SSH, ensure that you meet the following prerequisites:
-
You have Git installed on your local machine. For instructions, see Install Git. Ensure that your Git version is 1.9 or later by running the
git --versioncommand. -
An OpenSSH client is required. GNU/Linux, macOS, and Windows 10 include a built-in OpenSSH client.
-
Keep your SSH client up to date. Versions earlier than 6.5 may have security vulnerabilities because they use MD5 signatures.
Configure SSH keys
-
In Git Bash, run the following command to generate an SSH key. When prompted to "Enter file in which to save the key", specify a custom path and filename, such as ~/.ssh/codeup_1, to distinguish the key for each account, and then press Enter.
ssh-keygen -t rsa -C "<your_email@example.com>" Generating public/private rsa key pair. Enter file in which to save the key (~/.ssh/id_rsa):<Enter a custom name to distinguish the keys> -
Add the SSH keys to your Alibaba Cloud DevOps accounts. Log on to Alibaba Cloud DevOps with Account A. On the Codeup page, in the upper-right corner, navigate to . Paste the contents of the corresponding .pub file into the key field and save your changes. Repeat this process for Account B.
-
Edit the ~/.ssh/config file:
# Account A Host codeup_1 HostName codeup.aliyun.com IdentityFile ~/.ssh/codeup_1 PreferredAuthentications publickey IdentityAgent none IdentitiesOnly yes # Account B Host codeup_2 HostName codeup.aliyun.com IdentityFile ~/.ssh/codeup_2 PreferredAuthentications publickey IdentityAgent none IdentitiesOnly yes-
HostName: The service address of the hosting platform.
-
Host: An alias for convenient command line use.
-
IdentityFile: The path to the identity file (private key).
-
-
Command line operations
Switch accounts from the command line: When you push or pull code, you can switch between your local accounts. To do this, modify the SSH clone URL of the code repository. For example, if the original clone URL is
git@codeup.aliyun.com:me/Codeup-Demo.git, switch accounts by replacingcodeup.aliyun.comwith theHostalias defined in your~/.ssh/configfile:git@codeup_1:me/Codeup-Demo.git git@codeup_2:me/Codeup-Demo.gitYou can also run the following command to verify which account is associated with a specific key alias:
ssh -t git@codeup_1A successful connection returns output similar to the following:
xxw@xxwPC > ssh -t git@codeup_1 Welcome to Codeup, haoyurenzhu! Connection to codeup.aliyun.com closed.
More information
For more information about SSH configuration, see the ssh config documentation.