Linux SSH Commands and Remote Access

SSH, or Secure Shell, is a protocol used to securely connect to and manage remote Linux systems over a network. It is widely used for server administration, cloud infrastructure, troubleshooting, and secure file transfers.

What is SSH?

SSH provides an encrypted connection between a client and a remote server. After authentication, users can execute commands, manage files, configure services, and perform administrative tasks on the remote system.

TEXT
Local Computer → Encrypted SSH Connection → Remote Linux Server

How to Connect Using SSH

The ssh command connects to a remote host using a username and hostname or IP address.

BASH
ssh user@server-ip
ssh user@example.com

Using a Custom SSH Port

SSH commonly uses port 22, but administrators can configure a different port. The -p option specifies the port used for the connection.

BASH
ssh -p 2222 user@example.com

SSH Key Authentication

SSH keys provide an alternative to password authentication. A key pair contains a private key that stays on the client and a public key that can be installed on the remote server.

BASH
ssh-keygen -t ed25519
ssh-copy-id user@example.com
ssh user@example.com

Private Key Security

The private SSH key should be protected carefully. Its permissions should normally restrict access so that other users cannot read the key.

BASH
chmod 600 ~/.ssh/id_ed25519

Copying Files with scp

The scp command can securely copy files between local and remote systems using SSH.

BASH
scp file.txt user@example.com:/home/user/
scp user@example.com:/home/user/file.txt .

Using SFTP

SFTP provides an interactive way to transfer and manage files over an SSH connection.

BASH
sftp user@example.com
ls
put file.txt
get file.txt
exit

SSH Command Table

CommandPurposeExample
sshConnect to a remote systemssh user@example.com
ssh-keygenCreate SSH keysssh-keygen -t ed25519
ssh-copy-idInstall a public keyssh-copy-id user@example.com
scpCopy files over SSHscp file.txt user@example.com:/tmp/
sftpTransfer files interactivelysftp user@example.com

Running Remote Commands

SSH can execute a command on a remote server without opening an interactive shell.

BASH
ssh user@example.com 'uptime'
ssh user@example.com 'df -h'

SSH Configuration

The SSH client configuration file can simplify connections by defining host aliases, usernames, ports, and identity files.

BASH
nano ~/.ssh/config

Host myserver
    HostName example.com
    User admin
    Port 22
    IdentityFile ~/.ssh/id_ed25519

Common SSH Connection Problems

  • Incorrect username or hostname
  • Wrong SSH port
  • Firewall blocking the connection
  • SSH service not running
  • Incorrect key permissions
  • Public key not installed correctly

Basic SSH Troubleshooting

BASH
ssh -v user@example.com
systemctl status ssh
ss -tlnp | grep :22

Common SSH Security Practices

  • Use strong authentication methods
  • Protect private SSH keys
  • Prefer key-based authentication where appropriate
  • Limit unnecessary remote access
  • Keep the SSH server updated
  • Use firewall rules and access controls

Common Mistakes to Avoid

  • Sharing private SSH keys
  • Using overly permissive key permissions
  • Disabling host key verification without understanding the risk
  • Allowing unnecessary users to access servers
  • Exposing SSH access broadly when it is not required

Advanced SSH Concepts

  • SSH agent forwarding
  • Port forwarding
  • SSH tunneling
  • Jump hosts
  • ProxyJump
  • Connection multiplexing

Practice Exercises

  • Connect to a test Linux server using SSH
  • Generate an Ed25519 SSH key pair
  • Configure key-based authentication
  • Copy a file using scp
  • Transfer files using SFTP
  • Run a remote command through SSH
  • Create an SSH client configuration alias

Conclusion

SSH is one of the most important tools for securely managing Linux servers remotely. By learning ssh, SSH keys, scp, SFTP, and basic troubleshooting commands, administrators can efficiently manage remote systems.

Note: Note: Protect private keys carefully and verify the identity of remote hosts before trusting new SSH connections.