Connecting remotely to your machine is a common necessity for those who work with servers, both professionally and personally. SSH (Secure Shell) is one of the safest and most efficient methods to do so. In this article, we will see how to use SSH to connect to a remote machine (like a VPS), whether you are using Linux, Windows or MacOS.
What is SSH?
SSH, or Secure Shell, is a network protocol that allows for secure connections between two computers. By using encryption, SSH ensures that transmitted data cannot be intercepted or altered.
Connecting to the SSH Server from Linux or macOS
You can connect from another Linux or MacOS system using the terminal. Use the following command, replacing username with your username and hostname with the IP address or domain name of the remote server:
ssh username@hostname
If the SSH server is configured to listen on a port other than 22, use the -p option to specify the port:
ssh -p 2222 username@hostname
Connecting to the SSH Server from Windows
On Windows, you can use PuTTY, a free and open-source SSH client. Download PuTTY from the official website and install it.
- Open PuTTY.
- In the “Host Name (or IP address)” section, enter the IP address or domain name of the remote server.
- Make sure the port is correct (default is 22).
- Click “Open” to start the connection.
Using OpenSSH in PowerShell
Windows 10 and later versions include the OpenSSH client as a built-in feature in PowerShell. This allows Windows users to perform SSH connections and execute commands on remote servers directly from the command line interface.
Improving SSH Security
To enhance the security of your SSH connection, consider the following practices:
-
Use SSH Keys Instead of Passwords: SSH keys are more secure than passwords. You can generate a key pair with the
ssh-keygencommand and copy the public key to the remote server usingssh-copy-id. -
Disable Root Access: Edit the configuration file
/etc/ssh/sshd_configto prevent direct root access. Find the linePermitRootLoginand set it tono. -
Use a Non-Standard Port: Changing the SSH server listening port can reduce the risk of automated attacks.
-
Configure the Firewall: Ensure that only SSH connections are allowed through the firewall.
Conclusion
SSH is a powerful tool for securely connecting and managing remote machines. By following these steps, you can configure and use SSH on Linux, Windows, or a VPS. Always remember to follow best security practices to protect your data and systems.