Connecting to Linux Server via SSH
Detailed guide on how to connect to a Linux server via SSH
SSH (Secure Shell) is a protocol for secure remote access to a Linux server. This guide covers various methods of connecting to a server via SSH.
What is SSH?
SSH (Secure Shell) is a cryptographic network protocol for secure remote management of operating systems. It provides an encrypted connection between client and server, protecting transmitted data.
Preparation for Connection
Before connecting, make sure you have:
- Server IP address — the public IP address of your VPS/VDS server
- SSH port — usually port 22 (may be changed by administrator)
- Username — usually
rootor another username created by the administrator - Password or SSH key — authentication credentials
Connecting via SSH on Windows
Method 1: Using PowerShell (Windows 10/11)
Modern versions of Windows have built-in SSH support in PowerShell and Command Prompt.
- Open PowerShell or Command Prompt (Win + R, type
cmdorpowershell). - Execute the connection command:
For example:ssh username@ip-addressssh root@192.168.1.100 - On first connection, the system will ask to confirm the key fingerprint. Type
yes. - Enter the password (password input is not displayed).
Method 2: Using PuTTY
PuTTY is a popular SSH client for Windows.
- Download and install PuTTY from the official website: https://www.putty.org/
- Launch PuTTY.
- In the "Host Name (or IP address)" field, enter your server's IP address.
- Specify the port (usually 22) in the "Port" field.
- Select connection type "SSH".
- Click "Open".
- In the terminal that appears, enter your username, then password.
Method 3: Using Windows Terminal
Windows Terminal is a modern terminal from Microsoft.
- Install Windows Terminal from Microsoft Store (if not already installed).
- Open Windows Terminal.
- Execute the command:
ssh username@ip-address - Enter password when prompted.
Connecting via SSH on Linux and macOS
On Linux and macOS, SSH client is usually installed by default.
- Open terminal.
- Execute the connection command:
For example:ssh username@ip-addressssh root@192.168.1.100 - On first connection, confirm the key fingerprint by typing
yes. - Enter the user password.
Connecting with Port Specification
If the SSH server uses a non-standard port (not 22), specify the port in the command:
ssh -p 2222 username@ip-address
Connecting Using SSH Key
Using SSH keys is more secure than passwords.
Creating SSH Key (on Linux/macOS or Windows with OpenSSH)
- Create a key pair:
ssh-keygen -t rsa -b 4096 -C "your_email@example.com" - Press Enter to save in the default directory (
~/.ssh/id_rsa). - Enter a passphrase (can be left empty) or set a strong password.
- Copy the public key to the server:
Or manually:ssh-copy-id username@ip-addresscat ~/.ssh/id_rsa.pub | ssh username@ip-address "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"
Connecting with Key
After setting up the key, connection happens automatically:
ssh username@ip-address
Troubleshooting Common Issues
"Connection refused" Error
- Check that SSH service is running on the server:
sudo systemctl status sshd - Make sure SSH port is open in firewall
- Verify IP address and port are correct
"Permission denied" Error
- Check username and password are correct
- Make sure the user has access rights to the server
- Check
~/.ssh/authorized_keysfile settings on the server (for keys)
"Host key verification failed" Error
This error occurs when the server key has changed. To resolve:
- Remove the old entry from
~/.ssh/known_hostsfile:ssh-keygen -R ip-address - Connect again and confirm the new key.
Additional SSH Commands
Copying Files via SCP
# Copying file to server
scp file.txt username@ip-address:/path/to/destination
# Copying file from server
scp username@ip-address:/path/to/file.txt ./
# Copying directory
scp -r folder username@ip-address:/path/to/destination
Executing Command on Remote Server
ssh username@ip-address "command"
For example:
ssh root@192.168.1.100 "uptime"
SSH Security
Recommendations for secure SSH usage:
- Use SSH keys instead of passwords — this is a more secure authentication method
- Disable password login for root user (if possible)
- Change default SSH port (22) to a non-standard one
- Use strong passwords or keys with passphrase
- Limit access by IP addresses in firewall settings
Conclusion
Now you know how to connect to a Linux server via SSH using various methods. SSH is the standard and secure method for remote server management. Regularly update your system and monitor the security of your connections.
22.09.2024