SSH Service Guide
9/1/26Less than 1 minute
SSH Service Guide
SSH (Secure Shell) is a secure protocol for remote login and other network services. It provides an encrypted communication channel.
Note
SSH has become the standard tool for Linux/Unix system administration, replacing insecure protocols such as Telnet and rlogin. Beyond remote login, it also supports file transfer, port forwarding and more.
Installing SSH
On Debian/Ubuntu
sudo apt update
sudo apt install openssh-serverOn CentOS/RHEL
sudo yum install openssh-serverConfiguring SSH
The SSH configuration file is located at /etc/ssh/sshd_config.
Sample configuration
# Port number
Port 22
# Listen addresses
ListenAddress 0.0.0.0
ListenAddress ::
# Allowed users
AllowUsers user1 user2
# Disable password authentication, key authentication only
PasswordAuthentication no
PubkeyAuthentication yes
# Enable X11 forwarding
X11Forwarding yes
# Log level
LogLevel INFOExplanation
Port: the port the SSH service listens on.ListenAddress: the addresses the SSH service listens on.AllowUsers: the list of users allowed to log in.PasswordAuthentication: whether password authentication is allowed.PubkeyAuthentication: whether public key authentication is allowed.X11Forwarding: whether X11 forwarding is enabled.LogLevel: the log level.
Starting and Managing the SSH Service
sudo systemctl start ssh
sudo systemctl enable ssh
sudo systemctl status sshUsing SSH
Connecting to a remote server
ssh username@hostnameUsing SSH key authentication
Generate an SSH key pair:
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"Copy the public key to the remote server:
ssh-copy-id username@hostnamePort forwarding
Forward a local port to a remote port:
ssh -L local_port:localhost:remote_port username@hostname