This guide covers how to set up and configure ssh on a Linux VPS. Whether you're running a production environment or a development setup, these instructions will help you get started quickly and securely.
Prerequisites
- Basic familiarity with the Linux command line
- Root or sudo access to the server
- A registered domain name (for public-facing services)
- An SSH client installed on your computer
- A Kazepute account (sign up at kazepute.com)
Initial Setup Steps
For production deployments, consider implementing high availability by running multiple instances behind a load balancer. This approach provides both redundancy and improved performance under heavy load.
# Connect to your VPS via SSH
ssh root@your-server-ip
# Update the system
sudo apt update && sudo apt upgrade -y
# Set the hostname
sudo hostnamectl set-hostname myserver
# Set timezone
sudo timedatectl set-timezone America/New_York
The configuration above sets the recommended values for a VPS with 2-4GB of RAM. Adjust the memory-related settings proportionally if your server has different specifications.
Configuring Your Environment
It's recommended to test this configuration in a staging environment before deploying to production. This helps identify potential compatibility issues and allows you to benchmark performance differences.
# Create a non-root user
adduser deploy
usermod -aG sudo deploy
# Set up SSH key authentication
mkdir -p /home/deploy/.ssh
chmod 700 /home/deploy/.ssh
nano /home/deploy/.ssh/authorized_keys
chmod 600 /home/deploy/.ssh/authorized_keys
chown -R deploy:deploy /home/deploy/.ssh
The configuration above sets the recommended values for a VPS with 2-4GB of RAM. Adjust the memory-related settings proportionally if your server has different specifications.
Deploying Your First App
Before making changes to the configuration, always create a backup of the existing files. This ensures you can quickly roll back if something goes wrong during the setup process.
# Connect to your VPS via SSH
ssh root@your-server-ip
# Update the system
sudo apt update && sudo apt upgrade -y
# Set the hostname
sudo hostnamectl set-hostname myserver
# Set timezone
sudo timedatectl set-timezone America/New_York
This configuration provides a good balance between performance and resource usage. For high-traffic scenarios, you may need to increase the limits further.
Essential Tools
It's recommended to test this configuration in a staging environment before deploying to production. This helps identify potential compatibility issues and allows you to benchmark performance differences.
# Create a non-root user
adduser deploy
usermod -aG sudo deploy
# Set up SSH key authentication
mkdir -p /home/deploy/.ssh
chmod 700 /home/deploy/.ssh
nano /home/deploy/.ssh/authorized_keys
chmod 600 /home/deploy/.ssh/authorized_keys
chown -R deploy:deploy /home/deploy/.ssh
These commands should be run as root or with sudo privileges. If you're using a non-root user, prefix each command with sudo.
Wrapping Up
Following this guide, your ssh setup should be production-ready. Keep an eye on resource usage as your traffic grows and don't forget to test your backup and recovery procedures periodically.