Scenario
This section describes how to use SSH key pair to remotely log in to the Linux cloud server in Windows and Linux environments.
Login with SSH key pair, no password required. This method provides greater security and convenience.
Prerequisites
· The Linux cloud server is in the Running state.
· Usually, the default username for Linux OS is "root", while the default username for CoreOS is "core".
· You have obtained the key pair file used to create the Linux cloud server, which is the private key.
· Port 22 has been opened to the inbound security group where the Linux cloud server is located.
· Linux cloud server firewall is not enabled or port 22 is released after it is enabled.
· The SSH login tool you are using (e.g. PuTTY) is properly configured and has network connectivity with the Linux cloud server. If you use a terminal on the public network to log in, you need to bind an elastic IP address to your Linux cloud server. If you use this method to log in over the Intranet, you do not need to bind the Elastic IP, such as VPN or Cloud Dedicated Access.
Note
The Linux remote login port is usually modified for security reasons. If you want to modify the default login port, see Security Hardening for SSH Login on Linux Server.
locally using Windows OS
To log in to the Linux cloud server locally using the Windows operating system, you can use PuTTY as follows:
Method 1: Log in with PuTTY.
Let's take PuTTY as an example to introduce how to log into Linux cloud server. Before using PuTTY to log in to Linux cloud server, you need to convert the format of private key file into .ppk.
1. Check if the private key file is already in .ppk format.
· If it is, go to Step 7.
· If not, go to step 2.
1. Download PuTTY and PuTTYgen at the following link: https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html
Note
PuTTYgen is a key generator that creates key pairs and generates a pair of public and private keys for PuTTY.
1. Run PuTTYgen.
2. In the Actions area, click Load to import the private key file you saved when you created the Linux cloud server. Note that when importing, make sure the All files(.) format is selected.
3. Click Save private key.
4. Save the converted private key to local, for example, kp-101.ppk.
5. Double-click PUTTY.EXE to open PuTTY Configuration.
6. In Session, enter the elastic IP address of the Linux cloud server into the Host Name (or IP address) input box.
7. In Connection > Data, enter the image's username into Auto-login username.
8. Under the Private key file for authentication configuration item in Connection > SSH > Auth, click Browse and select the converted key file.
9. Click Open to log in to the Linux cloud server.
Method 2: Log in with Xshell
If you want to use the Xshell tool to log in to the Linux cloud server, please follow the steps below:
1. Open the Xshell tool.
2. Use elastic IP to execute the following command to remotely connect Linux cloud server via SSH:
ssh username@elastic IP
1. (Optional) If the system pops up a prompt window showing SSH Security Warning, click Accept and Save.
2. Select Public Key and click Browse in the User Key(K) column.
3. In the User Key window, click Import.
4. Select the locally saved key file and click Open.
5. Click OK to log in to the Linux cloud server.
locally using Linux OS
If you log in to the Linux cloud server locally using the Linux operating system, you can log in as follows. The following takes the private key file named "ssh-example.pem" as an example:
1. Open the terminal and enter the directory where the private key file is saved
2. Use the following command to set access permissions for the private key file:
chmod 400 /path/ssh-example.pem
Note
"/path" in the above command refers to the storage path of the private key file.
1. Execute the following command to log in to the Linux cloud server.
ssh -i /path/ssh-example.pem default username@elastic IP
Assuming that the default username of the Linux cloud server is "root" and the Elastic IP is 9.9.9.9, the command is as follows:
ssh -i /path/ssh-example.pem root@9.9.9.9
Note
"/path" refers to the storage path of the private key file.
The elastic IP address is the elastic IP address bound to the Linux cloud server.