SSH, or Secure Shell, is a cryptographic network protocol used to securely access and manage remote servers. Setting up an SSH server on Arch Linux allows you to connect to your system remotely in a secure manner.
In this comprehensive 2600+ word guide, we will walk through installing, configuring, optimizing, and troubleshooting an SSH server on Arch Linux.
Prerequisites
Before starting, make sure you have root access to your Arch Linux system. You‘ll need to execute some commands with sudo or as root.
It‘s also best to have your system fully updated before installing new software:
sudo pacman -Syu
Keeping your system updated is crucial for security and ensures you have the latest stable packages. Newer package versions frequently include patches for vulnerabilities.
Step 1 – Install OpenSSH
Arch Linux includes OpenSSH in its default repositories, making installation easy. Execute the following command:
sudo pacman -S openssh
This installs the OpenSSH server and client programs, including sshd, ssh, scp, and other tools. As one of the most widely adopted SSH implementations, OpenSSH is trusted by major enterprises like Google, Facebook, IBM, etc. due to its track record and reputation for quality.
Here‘s an overview of the packages installed:
| Package | Description |
|---|---|
| openssh | Meta package pulling in ssh client/server |
| openssh-clients | SSH client tools (ssh, scp) |
| openssh-server | SSH daemon and utilities (sshd) |
| openssh-keychain | SSH helper to manage keys |
Step 2 – Start and Enable the SSH Service
With OpenSSH installed, we need to start the sshd service and enable it to automatically start on boot:
sudo systemctl start sshd
sudo systemctl enable sshd
Enabling sshd.service ensures it will run persistently across reboots without needing to manually restart it.
Check that it is actively running:
sudo systemctl status sshd
You should see output indicating the service is active and running:
sshd.service - OpenSSH Daemon
Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: disabled)
Active: active (running) since Sat 2023-02-11 11:07:44 EST; 14s ago
If you do not see it active, debug your installation before proceeding.
Step 3 – Adjust the Firewall
If using a firewall like ufw or iptables on your system, you need to allow incoming connections on port 22, which is the default SSH port:
sudo ufw allow ssh
sudo ufw enable
For other firewalls like nftables or frontend proxies, simply open port 22 TCP inbound. This gives remote SSH clients access to your SSH server.
Neglecting to permit traffic to port 22 is the most common connectivity issue and source of "SSH connection refused" errors. SSH utilizes this standardized port by default.
Step 4 – Connect Remotely
You can now connect to your Arch server remotely using SSH from another Linux, macOS, or Windows machine that has an SSH client installed. This allows you to access the command line or transfer files securely.
To connect from Linux or macOS, use the native ssh command line program:
ssh username@your_server_ip
You will need to substitute your server‘s public IP address and your username on that system.
For example:
ssh john@192.168.1.100
On Windows, you can use PuTTY to connect instead. Just type your server IP address, set the connection type to SSH, and connect using port 22.
After authenticating successfully by entering your password (or SSH key passphrase if enabled), you will get remote shell access! Try executing some commands or editing files to validate connectivity.
Step 5 – Backup SSH Configuration
Before making any custom SSH configuration changes, we should backup the original configuration file. This allows us to restore working defaults if needed:
sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.original
We can now edit our active sshd_config while keeping sshd_config.original intact as a baseline fallback.
I would also suggest making your alterations in a version control system like git to track changes over time.
Step 6 – Disable Root Login
Permitting direct root logins via SSH is extremely insecure and should be avoided. We can explicitly disable this by editing sshd_config:
sudo nano /etc/ssh/sshd_config
Find the line for PermitRootLogin and change it to no:
PermitRootLogin no
This prevents attackers from brute forcing or guessing the root password. They will not even be able to attempt signing in as root remotely.
Now restart the SSH service to apply this change:
sudo systemctl restart sshd
Root will no longer be allowed to directly SSH in. Admins will need to first connect as a normal user, then use su or sudo to elevate privileges. This compartmentalizes credentials and adds an extra layer of security.
Step 7 – Disable Password Authentication
Another hardening best practice is to disable password authentication entirely, requiring use of SSH keys instead.
SSH keys utilize asymmetric cryptography, meaning a private and public key pair. The private key is kept only on user machines while the public key gets stored on your Arch server. This separates the authentication factor (private key file) from the server itself for increased security.
Keys also avoid human-generated passwords susceptible to brute forcing, dictionary attacks, social engineering and theft. Machine generated crypto keys have far greater entropy making them extremely difficult to crack.
Let‘s disable plain password auth:
sudo nano /etc/ssh/sshd_config
Find the line for PasswordAuthentication and change it to no:
PasswordAuthentication no
Save changes and restart sshd:
sudo systemctl restart sshd
Users will now be forced to utilize SSH keys to authenticate remotely.
But existing SSH connections will be knocked offline when removing password support. So make sure you have configured keys for each user first before restarting sshd!
Step 8 – Set Up SSH Keys
With password-based authentication disabled, your users must configure SSH keys to enable remote logins:
For each user needing access, follow this process on their client machine:
- Generate an SSH keypair with
ssh-keygen - Copy public key to server‘s
~/.ssh/authorized_keys - Set proper ownership and file permissions
This will allow that specific user‘s client to authenticate using their private key against the public key you‘ve stored on your server.
For example, to generate keys for the john user:
ssh-keygen -t rsa -b 4096
Hit enter to accept default filenames and key passphrase prompts as desired.
Then copy the public key to the server as john:
ssh-copy-id -i ~/.ssh/id_rsa.pub john@192.168.1.100
Alternatively, you can manually append keys to ~john/.ssh/authorized_keys if needed.
Double check permissions and ownership afterwards:
chown -R john:john /home/john/.ssh
chmod 700 /home/john/.ssh
chmod 600 /home/john/.ssh/authorized_keys
Repeat the key generation, copy, and permission lockdown for all remote users and admins that require access.
Step 9 – Change the Listening Port
By default, SSH listens on TCP port 22 for incoming connections. Changing to a non-standard higher port can obscure SSH from generic network probes and deter opportunistic botnet attacks.
Edit sshd_config:
sudo nano /etc/ssh/sshd_config
Find the Port line and change it, for example to 22222:
Port 22222
Save modifications and restart the sshd process:
sudo systemctl restart sshd
Clients will now connect to your new defined port instead of 22 when accessing SSH.
Remember to permit traffic to the new TCP port in your firewall/security groups as well. Failure to do so will break remote access.
While optional, altering the listening SSH port hinders cheap "shallow" scans tracking port 22 across networks. Port obfuscation forces adversaries to work harder to discover accessible SSH entry points into your infrastructure.
Step 10 – Limit Access
You can restrict SSH authentication to specific users, groups, or IP addresses by adding conditional access rules.
For example, to whitelist SSH for only your own public broadband IP:
AllowUsers username@xxx.xxx.xxx.xxx
Likewise, to permit an entire existing system group:
AllowGroups sshusers
Or combine criteria as needed:
AllowUsers adminuser@xxxxxx
AllowGroups ssh_admins
At a minimum, avoid extremely permissive settings like AllowUsers * or AllowGroups *.
Restart sshd after making access control changes:
sudo systemctl restart sshd
Enforcing restrictions prevents lateral movement across your environment if one system gets compromised. Limiting access increases SSH server resilience against malicious actors.
Step 11 – Configure Key Regeneration
By default, OpenSSH never automatically rotates host keys. While your key only shields new sessions, proactively regenerating it on an ongoing basis ensures forward secrecy.
To regenerate your identification keys once a month automatically:
echo "0 0 1 * * root /usr/bin/ssh-keygen -A" >> /etc/crontab
Remember to distribute any newly generated public keys to your users following this, otherwise existing SSH keys will fail while attempting connections.
Regularly refreshing keys reduces long-term decryption risks as computing power grows exponentially. What is secure now may not withstand advances in quantum computing able to brute force older key lengths.
Step 12 – Enable Audit Logging
To determine accountability and monitor for anomalies, enable verbose SSH logging showing connection details and timestamps.
First, create the logfile itself append timestamp:
sudo touch /var/log/sshd_config-$(date +%F).log
Next configure sshd logging directives:
SyslogFacility AUTH
LogLevel INFO
StrictModes yes
MaxAuthTries 3
LoginGraceTime 20
PermitUserEnvironment no
LogFormat "%h %t %T %v"
LogLevel VERBOSE
This logs user, timestamp, session times, and client IP per SSH login attempt – successful or failed.
StrictModes tightens control, while shorter timeouts thwart denial of service.
Finally restart sshd to initialize the new logfile:
sudo systemctl restart sshd
Now you can monitor logs in real-time with tail -f for anomalies or record them in a central SIEM analytics platform to establish audit history.
Step 13 – Benchmark Performance
As a best practice following configuration changes, benchmark SSH to validate maintained performance levels under load.
Consider using a tool like weighttp or wrk2 to simulate concurrent SSH user sessions against your server.
For example, hitting the SSH process utilizing 10 connection threads:
weighttp -t 10 -c 10 -n 100000 ssh://username@server_ip:22222
This can identify latency or bandwidth bottlenecks introduced accidentally via configuration tweaks. You want to sustain acceptable response times for your user base.
Step 14 – Automate Deployment
Once satisfied with your optimized SSH configuration, consider automating deployment across environments using tools like Ansible, Puppet or Terraform.
For instance, Terraform providers allow declaring sshd hardening:
resource "null_resource" "ssh-hardening" {
provisioner "remote-exec" {
inline = [
"sudo sed -i ‘/^PasswordAuthentication /c\PasswordAuthentication no‘ /etc/ssh/sshd_config",
"echo AllowUsers user1 >> /etc/ssh/sshd_config",
]
}
connection {
type = "ssh"
user = "admin"
private_key = file("~/.ssh/id_rsa")
host = openstack_compute_instance_v2.myserver.access_ip_v4
}
}
This enables easy replication into other environments matching compliance requirements consistenly at scale. Infrastructure as code approaches help avoid costly manual misconfiguration.
For one-off systems, executing modular Bash scripts can also work to quickly roll out Secure Shell.
Troubleshooting Common SSH Issues
Here are some resolutions for frequent sshd trouble areas on Arch Linux:
Error: Protocol mismatch (or less commonly Host key mismatch)
This indicates the local SSH client version differs from the remote SSH server version, causing a handshake failure.
- Update both client and server to latest available OpenSSH release using
pacman -Syu openssh openssh-clients
Error: Connection timed out
- Validate TCP port SSH is listening on is permitted in network firewalls/security groups
- Disable any third party VPN client or proxy temporarily to test bare connectivity
- Check for intermediate device filtering via Wireshark trace during connection attempt
Error: No route to host
- Double check SSH server IP address or hostname provided
- Ping remote server IP to confirm host reachable over network
- Inspect routers and switches for any dead VLAN links or blackholing policies
Warning: Remote host identification change detected
- Often due to pivoting between SSH‘ing from laptop vs desktop clients
- Can manually remove prior host fingerprint entry from
~/.ssh/known_hostsif confident valid system - Best practice is to verify key fingerprints match remotely to confirm host authenticity
Error: Permission denied (publickey)
- Validate your local user SSH public key exists in remote server‘s
authorized_keysfile - Check SSH user home folder ownership and permissions follow security best practices above
Final Thoughts
Configuring a robust, reliable SSH server in Arch Linuxhas multiple facets beyond base installation. Actively hardening your configuration, validating performance under load, automating deployment, and troubleshooting issues all contribute to a comprehensive security posture and acceptance testing model.
Ideally you can now remotely access and manage your Arch Linux system securely with the fully-featured enhancements provided in this 2600+ word guide. SSH remains a fundamental network service to provide an encrypted conduit protecting your data in transit across untrusted networks.
With SSH properly deployed following these industry best practices, you have an encrypted gateway to tunnel traffic, backup systems, synchronize files or securely execute commands on remote servers.


