SSH and Remote Access

Commands for secure shell connections, key management, remote command execution, and session management

SSH Connection

ssh username@hostname

  • Connect to remote Debian server
  • Uses default port 22

ssh -p [port] user@host

  • Connect using custom port
  • Specify alternate SSH port

ssh -i [keyfile] user@host

  • Connect using private key
  • Key-based authentication

Key Management

ssh-keygen -t rsa -b 4096

  • Generate RSA key pair
  • 4096-bit encryption strength

ssh-copy-id user@host

  • Copy public key to remote server
  • Enables passwordless login

chmod 600 ~/.ssh/id_rsa

  • Set correct key permissions
  • Required for security

SSH Configuration

sudo nano /etc/ssh/sshd_config

  • Edit SSH daemon config
  • Server-side settings

sudo systemctl restart ssh

  • Restart SSH service
  • Apply configuration changes

sudo ufw allow ssh

  • Allow SSH through firewall
  • Opens port 22

Remote Commands

ssh user@host 'command'

  • Execute single remote command
  • Returns to local shell

scp file user@host:/path/

  • Copy files to remote server
  • Secure file transfer

rsync -av local/ user@host:remote/

  • Sync directories remotely
  • Preserves permissions

Session Management

screen -S sessionname

  • Create named screen session
  • Survives SSH disconnection

tmux new -s sessionname

  • Create tmux session
  • Alternative to screen

Example Config

1
2
3
4
5
# /etc/ssh/sshd_config
Port 2222
PermitRootLogin no
PasswordAuthentication no
PubkeyAuthentication yes