Overview
sshd runs in the background, by default listening for SSH client connections on TCP port 22. All communication is encrypted for security, and it supports various authentication methods (password, public key, etc.).
Key Features
- Provides secure remote shell access
- Supports file transfers via SCP/SFTP
- Offers port forwarding and tunneling capabilities
- Supports various authentication mechanisms (password, public key)
Default Configuration File
The behavior of sshd is primarily controlled through the following configuration file.
- Path: /etc/ssh/sshd_config
Key Options
sshd is typically run as a system service, so direct command-line option usage is infrequent. However, some options can be useful for debugging or testing purposes.
Execution and Debugging
Generated command:
Try combining the commands.
Description:
`sshd` Executes the command.
Combine the above options to virtually execute commands with AI.
Usage Examples
sshd is typically controlled via a service manager like systemd.
Check sshd Service Status
sudo systemctl status sshd
Checks the current status of the sshd service.
Restart sshd Service
sudo systemctl restart sshd
Restarts the sshd service to apply configuration changes.
Enable sshd Service (Start on Boot)
sudo systemctl enable sshd
Configures the sshd service to start automatically when the system boots.
Validate sshd Configuration File
sudo sshd -t
Checks the sshd_config file for syntax errors.
Run sshd in Debug Mode (for testing)
sudo sshd -d -p 2222
Runs sshd in debug mode on a different port (e.g., 2222) than the default. Useful for testing without affecting the live service.
Installation
sshd is part of the OpenSSH server package. It is usually installed by default on most Linux distributions. If it's not present, you can install it using the following commands.
Debian/Ubuntu Based Systems
sudo apt update
sudo apt install openssh-server
CentOS/RHEL/Fedora Based Systems
sudo yum install openssh-server # or sudo dnf install openssh-server
Tips & Considerations
sshd plays a critical role in system security. It is recommended to consider the following points when configuring it.
Security Enhancement Tips
- **Change Default Port**: Modify `Port 22` to another arbitrary high port number to reduce brute-force attacks.
- **Disable Root Login**: Set `PermitRootLogin no` to prevent direct login as the root user.
- **Disable Password Authentication and Use Public Key Authentication**: Set `PasswordAuthentication no` and enable public key authentication (`PubkeyAuthentication yes`) for enhanced security.
- **Restrict Allowed Users**: Use `AllowUsers` or `AllowGroups` options to explicitly specify which users or groups are allowed to SSH in.
- **Configure Firewall**: Set up a firewall (ufw, firewalld, etc.) to allow access only to the SSH port (default 22 or your changed port) from external sources.
Restart Service After Configuration Changes
After modifying the `sshd_config` file, you must restart the service using the command `sudo systemctl restart sshd` for the changes to take effect.
Test Connection
After making configuration changes, always test your SSH connection from another terminal to ensure the changes have been applied correctly. It's advisable to perform this test while keeping your current session active.