Tired of entering your password every time you run
ssh root@xxx? Does the terminal freeze after ten minutes of inactivity? This article shares a complete solution that lets you log in to Alibaba Cloud ECS from an Ubuntu terminal with a single command, no password required, while keeping the connection from ever freezing.
Background: Two Annoying Problems
As a developer who frequently connects to Alibaba Cloud ECS from an Ubuntu terminal, I run this command every day:
ssh root@121.40.248.29Then I type a long password.

Even more frustratingly, sometimes I step away to grab a glass of water or read a document, only to come back and find the terminal “dead”—pressing Ctrl+C does nothing, pressing Enter does nothing either. I have no choice but to close the window, which then prompts “some processes are still running.”

On my Alibaba Cloud ECS instance in Hangzhou (Alibaba Cloud Linux 3), I figured out two simple and effective solutions through trial and error:
- SSH key-based passwordless login – say goodbye to entering passwords
- Configure keepalive heartbeat – say goodbye to frozen connections
Below is the complete walkthrough, accompanied by real screenshots from the console and terminal.
Step 1: Create a Key Pair in the Alibaba Cloud Console
Log in to the Alibaba Cloud ECS Console and find “Network & Security” > “Key Pairs” in the left navigation pane.

Click “Create Key Pair” to bring up the form:
- Key Pair Name: Enter a memorable name, such as
Ubuntu-26.04 - Creation Type: Select “Auto-Create Key Pair” (recommended; the system will generate a public key and automatically host it, while you download and keep the private key)
- Resource Group: Optional; generally, you do not need to select one and can just skip this

After clicking OK, the browser will automatically download a .pem file (the private key). This is your only chance to download it, so keep it safe. My file name is Ubuntu-26.04.pem.
Step 2: Bind the Key Pair to the ECS Instance
Find the Ubuntu-26.04 you just created in the key pair list, and click “Bind Key Pair”.

Check your target ECS instance (the one with IP 121.40.248.29), and click OK. The system will prompt: “Restarting the instance is required for it to take effect”. Confirm the instance restart during an off-peak period.
💡 You can restart from the console, or log in to the instance and run
reboot. The key pair binding only takes effect after the restart.
Step 3: Configure the Private Key and SSH Client Locally
Return to your local Ubuntu terminal (I am using a ThinkPad T570 + Ubuntu 26.04).
1. Move the Private Key File and Set Permissions
My Ubuntu-26.04.pem was downloaded to the ~/下载/ directory (a Chinese path). First, create the .ssh directory, then move and rename the file:
mkdir -p ~/.ssh
mv ~/下载/Ubuntu-26.04.pem ~/.ssh/aliyun.pem
chmod 600 ~/.ssh/aliyun.pem # 必须!否则 SSH 会报权限过宽的错误⚠️ If it was downloaded to
~/Downloads/, adjust the path accordingly.
2. Configure the SSH Client (Simplify the Login Command)
Edit (or create) the ~/.ssh/config file:
nano ~/.ssh/configAdd the following content:
Host aliyun
HostName 121.40.248.29
User root
IdentityFile ~/.ssh/aliyun.pem
ServerAliveInterval 60 # Keepalive heartbeat, sends an empty packet every 60 secondsSave and exit (Ctrl+X, then Y, then Enter).
Host aliyunis a custom alias; from now on, you only need to runssh aliyun.ServerAliveInterval 60is the key to solving the “no response after 10 minutes” issue.
3. Test Passwordless Login
ssh aliyunAs shown in the screenshot, I ran mv, chmod, and nano in succession, and finally ssh aliyun in one smooth flow. It displayed the welcome message and the last login time immediately, without any password prompt.

Step 4: The Principle Behind Fixing the Frozen Connection
The “no response after 10 minutes” issue occurred earlier because intermediate network devices (such as firewalls and NAT) considered the idle connection to have no data transmission and disconnected it. The purpose of ServerAliveInterval 60 is to have the local SSH client automatically send an empty “heartbeat” packet to the server every 60 seconds, keeping the connection active. Even if you stare blankly for an hour, the connection will not drop.
Security Recommendation: Restrict Security Group Source IPs
To further enhance security, I recommend configuring a security group in the Alibaba Cloud console to allow only your local public IP to access port 22:
- Run
curl ifconfig.melocally to get your current public IP. - Go to ECS Instance Details → Security Groups → Configure Rules → Inbound.
- Find the SSH (22) rule, and change the authorized object from
0.0.0.0/0to你的IP地址/32.
This way, even if the private key is accidentally leaked, no one else can log in to your server from a different IP.
Summary
Through these steps, I have completely said goodbye to:
- ❌ Entering a password every time
- ❌ The connection freezing for no reason after ten minutes
Now I just type ssh aliyun in the terminal to log in instantly. When I come back after doing other things, the terminal still responds smoothly. Moreover, the entire process uses no third-party software (like PuTTY); it relies purely on native SSH configuration and runs perfectly in an Ubuntu terminal.
If you are also troubled by the same issues, give this guide a try. I believe you can get it done in under ten minutes.
Final reminder: Keep the downloaded .pem private key file safe, and do not upload it to public code repositories. If you need passwordless login from multiple computers, you can reuse the same key pair (just copy the private key to the ~/.ssh/ directory on the other computers and set the permissions).
Test environment: Ubuntu 26.04 (local) + Alibaba Cloud Linux 3 (ECS, Hangzhou node)
If you have any questions, feel free to leave a comment and discuss.

