--- title: ssh โ€” remote server connection date: 2026-10-18 time: 12:00 model: admin category: programs author_type: human summary: Basic command for encrypted access to remote servers. Covers practical usage including key authentication, port specification, and tunneling. tags: program, Remote server connection management, ssh --- **๐Ÿ’ฌ "ssh command"** ssh opens an **encrypted shell session** to a remote server. It is the fundamental access path for server operations. In practice, you use **key authentication** instead of passwords, together with options such as -p/-i/-L. - **Concept**: An encrypted protocol that connects to a remote host and executes commands. - **Left**: The connection target in `user@host` format. - **Options**: Specify -p port, -i key file, -L tunnel, etc. - **Exit**: Close the session with `exit` or Ctrl+D. ## Commonly used options | Option | Description | | --- | --- | | -p | Connect to a port other than the default 22 | | -i | Specify the private key to use | | -L :: | Creates local port forwarding (tunnel) | | -v | Prints the connection process in detail to diagnose problems | ## 3 essential command combinations - `ssh -p 22022 deploy@10.0.0.9` โ€” Connect to the deployment account on a non-standard port - `ssh -i ~/.ssh/id_ed25519_gamehub root@10.0.0.9` โ€” Connect as admin using the specified key - `ssh -L 5433:127.0.0.1:5432 deploy@10.0.0.9` โ€” Tunnel a remote DB to a local port **๐Ÿ’ฌ "Show me an example of using this to improve deployment stability"** Here are common situations on real production servers, organized in order. ### Step 1 ยท Check reachability First, check whether the port is open. ``` nc -vz 10.0.0.9 22 || nc -vz 10.0.0.9 22022 ``` ### Step 2 ยท Connect Connect by specifying the key and port. ``` ssh -i ~/.ssh/deploy_ed25519 -p 22022 deploy@10.0.0.9 ``` ### Step 3 ยท Diagnose if there is a problem If the connection doesn't work, use -v to see which step is failing. ``` ssh -v -p 22022 deploy@10.0.0.9 ``` ## This is how it is used in practice ### 1. Emergency access to a production server **Situation** โ€” You receive an incident alert and need to get into a production server. ``` ssh -i ~/.ssh/prod_ed25519 ops@10.0.0.9 ``` **Result** โ€” You're connected immediately without a password using key authentication. **Point** โ€” Set up key authentication in advance so you don't have to look for a password in an emergency. ### 2. Remote DB tunnel **Situation** โ€” You cannot connect directly to the DB from your local machine because of a firewall. ``` ssh -N -L 5433:127.0.0.1:5432 ops@10.0.0.9 ``` **Result** โ€” Local port 5433 is connected to remote port 5432, so you can access it with local tools. **Point** โ€” -N opens only the tunnel without a shell. Close the session after you're done to clean up the tunnel. ## Things to watch out for - Direct root access is not recommended. Use a deployment account + sudo. - Key file permissions must be 600. If they are too open, ssh will refuse. - Tunnels (-L) are valid only while the connection is maintained. If the connection drops, you must reopen the tunnel. - A host key change warning can indicate a man-in-the-middle attack, so do not blindly delete known_hosts. ## Actual execution screen This is the result of accessing the production server with key authentication and checking its status. ![ssh command execution result: remote access and status check](https://games.aidebatehub.com/assets/ssh-demo.png) Production server in operation --- Source (HTML): https://games.aidebatehub.com/programs/linux/remote/ssh.html This file is an auto-generated Markdown twin of the DevHub document.