Connecting to VPS
SSH Basics
SSH (Secure Shell) is the industry standard for secure remote server management. It encrypts all data transmitted between your local machine and the VPS, preventing eavesdropping and man-in-the-middle attacks. Before connecting, you’ll need to understand SSH authentication methods.
First-time connection workflow:
- Open your terminal
- Enter this command (replace
your-vps-ipandyour-username):
<code class="language-bash"> ssh your-username@your-vps-ip</code>
- When prompted for a password, enter the password you set up for your VPS
Common issues:
- Connection refused: SSH service isn’t running (check firewall settings)
- Permission denied (publickey): SSH key isn’t properly configured (we’ll fix this next)
💡 Pro Tip: Always use SSH keys for production environments to avoid password prompts and enhance security.
Initial Setup
After your first connection, follow these steps to prepare your VPS for production:
- Update the system (critical for security patches):
<code class="language-bash"> sudo apt update && sudo apt upgrade -y</code>
Note: Uses apt for Ubuntu/RHEL systems
- Create a non-root user (best practice for security):
<code class="language-bash"> sudo adduser your-new-username</code>
Then grant sudo privileges:
<code class="language-bash"> sudo usermod -aG sudo your-new-username</code>
- Set up SSH keys for passwordless login (essential for automation):
<code class="language-bash"> ssh-keygen -t rsa -b 4096</code>
– Press Enter for default path (~/.ssh/id_rsa)
– Leave passphrase empty temporarily (set later for security)
Copy public key to VPS:
<code class="language-bash"> ssh-copy-id your-new-username@your-vps-ip</code>
- Install essential tools for Docker operations:
<code class="language-bash"> sudo apt install curl git -y</code>
- Verify your SSH key:
<code class="language-bash"> ssh your-new-username@your-vps-ip</code>
You should get a prompt without being asked for a password.
Why this matters: These steps create a secure foundation where you can deploy Docker containers without password prompts, while maintaining strict security controls. Always set a strong passphrase for your SSH key in production environments.
Summary
You’ve learned the fundamentals of connecting to your VPS and setting up the initial environment. This knowledge is critical for deploying Docker containers and managing your server securely.
😊