How to use SSH for remote access in Linux
· Category: Linux
Short answer
SSH provides encrypted remote shell access. Use key-based authentication for stronger security than passwords.
Steps
- Connect to a server:
ssh [email protected]
- Generate a key pair:
ssh-keygen -t ed25519 -C "[email protected]"
- Copy public key:
ssh-copy-id [email protected]
- Use a config file (
~/.ssh/config):
Host myserver
HostName server.example.com
User admin
IdentityFile ~/.ssh/id_ed25519
Tips
- Disable root login and password authentication in
/etc/ssh/sshd_config. - Use
ssh -Lfor local port forwarding. - Keep private keys encrypted and never share them.
Common issues
- Permission too open: private keys must be
chmod 600. - Connection refused: verify the server is running sshd and the port is open.