After you purchase an RDS Custom instance, you can connect to it from the command line.
Prerequisites
-
The RDS Custom instance is running.
-
You have configured logon credentials, such as a custom password or a key pair, for the RDS Custom instance.
If you use a key pair to connect to the RDS Custom instance, ensure the private key file (.pem) is saved on your local device. For more information, see Create an SSH key pair.
Step 1: Get the IP address
You can connect to an RDS Custom instance by using a private IP address or an Elastic IP Address (EIP).
|
Connection method |
Description |
Billing |
|
Private IP address |
You can connect to the RDS Custom instance only from an ECS instance in the same region and VPC. |
Data transfer is free. |
|
Elastic IP Address (EIP) |
You can connect from ECS instances (regardless of the region and VPC), on-premises servers, and common SSH clients such as OpenSSH, PuTTY, and Xshell. |
|
-
Log on to the RDS console. In the navigation pane on the left, choose RDS Custom > Custom Instances. In the top navigation bar, select a region.
-
Click the instance ID to go to the instance details page.
-
On the Basic Information page, in the Configuration Information section, get the private IP address or associate an EIP.
NoteWhen you associate an EIP, you can select an existing EIP or create a new one. To create an EIP, see Apply for an EIP.
Step 2: (Optional) Configure security group rules
If you connect by using an EIP, you must add your client's public IP address to the security group of the RDS Custom instance. Skip this step if you use a private IP address.
-
Log on to the RDS console. In the navigation pane on the left, choose RDS Custom > Custom Instances. In the top navigation bar, select a region.
-
Click the instance ID to go to the instance details page.
-
On the Basic Information page, in the Other Information section, get the security group ID of the RDS Custom instance.
-
Log on to the ECS console, find the security group of the RDS Custom instance, and add a security group rule. For more information, see Add a security group rule.
Step 3: Connect to the RDS Custom instance
This section uses an ECS instance to demonstrate how to connect to an RDS Custom instance.
Connect using a custom password
-
Log on to your ECS instance. For more information, see the Connect to an ECS instance section in Use the console to manage an ECS instance.
-
Run the following command to connect and enter the password for your RDS Custom instance when prompted.
ssh <username>@<ip_address>-
<username>: The username for your RDS Custom instance. The default isroot. -
<ip_address>: The IP address of your RDS Custom instance.
-
After you log on to the RDS Custom instance, avoid modifying the route table, iptables firewall rules, or network interface configurations (including restarting eth0) to prevent connection interruptions.
Connect using a key pair
By command
-
Log on to your ECS instance. For more information, see the Connect to an ECS instance section in Use the console to manage an ECS instance.
-
Upload your private key file (.pem) to the ECS instance. For example, you can upload it to the
~/.sshdirectory. -
Run the following command to change the permissions of the private key file:
chmod 400 <path_to_private_key_file.pem>Example:
chmod 400 ~/.ssh/custom_test.pem -
Run the following command to connect to the RDS Custom instance:
ssh -i <path_to_private_key_file.pem> <username>@<ip_address>Example:
ssh -i ~/.ssh/custom_test.pem root@172.26.XX.XX
By config file
-
Log on to your ECS instance. For more information, see the Connect to an ECS instance section in Use the console to manage an ECS instance.
-
Upload your private key file (.pem) to the ECS instance. For example, you can upload it to the
~/.sshdirectory. -
Run the following command to change the permissions of the private key file:
chmod 400 <path_to_private_key_file.pem>Example:
chmod 400 ~/.ssh/custom_test.pem -
Run the following commands to navigate to the
.sshdirectory in your home directory and then create and edit theconfigfile:cd ~/.ssh vim config -
In the config file, press
ito enter edit mode, and then add the following configuration:# An alias for the RDS Custom instance, used for the SSH remote connection. Host custom_test # The IP address of the RDS Custom instance. HostName 172.26.XX.XX # The port number. The default is 22. Port 22 # The logon account. The default is root. User root # The path to the .pem private key file on your machine. IdentityFile ~/.ssh/custom_test.pem -
Run the following command to restart the SSH service:
WarningIf the SSH service fails to restart, it may become unavailable and interrupt your services. We recommend performing this operation during off-peak hours.
service sshd restart -
Run the following command to connect to the RDS Custom instance:
ssh <alias_of_rds_custom_instance>Example:
ssh custom_test
After you log on to the RDS Custom instance, avoid modifying the route table, iptables firewall rules, or network interface configurations (including restarting eth0) to prevent connection interruptions.
More operations
You can use Alibaba Cloud Server Load Balancer (SLB) to efficiently forward traffic to your RDS Custom instance. This approach improves service availability and scalability, and enables public connections while protecting your internal network. For more information, see the following topics: