SSH (Secure Shell) is a cryptographic network protocol used for securely accessing a remote system. Whether you are a system administrator or a developer, knowing how to configure and use SSH is a vital skill.
This article will guide you through the process of installing and configuring SSH for secure remote access. We’ll cover key concepts, authentication methods, and common configurations.
Most Linux distributions come with SSH installed, but if it’s not, you can easily install it.
For Debian-based systems (Ubuntu, Debian):
sudo apt-get update sudo apt-get install openssh-server
For Red Hat-based systems (CentOS, Almalinux, Rocky linux, Fedora):
sudo yum install openssh-server
Open the main configuration file with a text editor:
sudo nano /etc/ssh/sshd_config
Make necessary adjustments, such as changing the default SSH port or disabling root login:
Port 2222 PermitRootLogin no
Restart the SSH service to apply changes:
sudo systemctl restart sshd
Generate a key pair:
Copy the public key to the remote server:
For more advanced SSH key configurations, you can refer to our detailed guide on SSH key security.
Connect to a remote server:
Specify a custom port:
ssh -p 2222 username@remote_host
- Change the default SSH port to reduce exposure to automated attacks.
- Use key-based authentication instead of password authentication.
- Regularly update the SSH package to patch vulnerabilities.
Setting up SSH for secure remote access is an essential task for anyone working with Linux servers. By following these instructions, you can ensure that your remote connections are secure and efficient.