Linux SSH and Secure File Transfer
SSH provides encrypted remote shells and file transfer. This article assumes basic navigation and permissions from Linux Users, Groups, and Permissions.
Install and verify the server
On Debian or Ubuntu:
sudo apt update
sudo apt install openssh-server
sudo systemctl enable --now ssh
sudo systemctl status ssh
Check the listening socket and firewall policy before testing from another host:
sudo ss -tlnp | grep ':22'
sudo ufw allow OpenSSH
Use a key
Generate a key on the client, not on the server:
ssh-keygen -t ed25519 -C 'admin@example.invalid'
ssh-copy-id user@server
ssh user@server
Protect the private key with a passphrase. Never copy it to a server or commit it to a repository.
Harden deliberately
After confirming key login in a second session, consider disabling password authentication and direct root login in /etc/ssh/sshd_config:
PasswordAuthentication no
PermitRootLogin no
Validate before reloading:
sudo sshd -t
sudo systemctl reload ssh
Do not disable password access until a tested key-based recovery path exists. A firewall, updates, rate limiting, and least-privileged accounts remain important.
Transfer files
scp ./backup.tar.gz user@server:/tmp/
scp user@server:/tmp/backup.tar.gz ./
For large or repeat transfers, rsync -av --progress -e ssh source/ user@server:/srv/backup/ can avoid retransmitting unchanged data.
Troubleshooting
ssh -vv user@server
sudo journalctl -u ssh --since '10 minutes ago'
Use hostnames or stable DNS records instead of relying on a container’s temporary IP address.