Linux SSH Commands
Overview
SSH (Secure Shell) is a protocol used to securely access and manage remote systems over a network. The SSH suite of commands provides a variety of tools for connecting to, configuring, and managing remote systems. This document covers basic and commonly used SSH commands.
Basic SSH Commands
ssh
Used to securely connect to a remote machine.
Example
ssh-keygen
Generates a new SSH key pair.
Example
ssh-keygen
# Prompts to generate a new SSH key pair; saves the private key and public key in the default location (~/.ssh/)
ssh-copy-id
Copies your SSH public key to a remote host's authorized keys.
Example
ssh-copy-id john@192.168.1.100
# Copies the public key to the remote host to enable passwordless login for user 'john'
scp
Securely copies files between hosts over SSH.
Example
scp localfile.txt john@192.168.1.100:/home/john/
# Copies 'localfile.txt' from the local machine to the '/home/john/' directory on the remote host
sftp
Secure File Transfer Protocol for transferring files over SSH.
Example
ssh-add
Adds SSH private keys to the SSH authentication agent.
Example
ssh-agent
Manages SSH keys and handles authentication for SSH sessions.
Example
Advanced SSH Commands
ssh -i
Specifies a private key file to use for authentication.
Example
ssh -i ~/.ssh/id_rsa john@192.168.1.100
# Connects to the remote host using the specified private key file
ssh -p
Specifies a port number for the SSH connection.
Example
ssh -L
Creates a local port forwarding.
Example
ssh -L 8080:localhost:80 john@192.168.1.100
# Forwards local port 8080 to port 80 on the remote host through SSH
ssh -R
Creates a remote port forwarding.
Example
ssh -R 9090:localhost:80 john@192.168.1.100
# Forwards remote port 9090 to port 80 on the local machine through SSH
ssh -C
Enables compression for the SSH connection.
Example
Summary
The SSH suite of commands provides powerful tools for securely managing and transferring data between systems. By mastering these commands, you can effectively perform remote administration and file transfers while maintaining secure connections. For more detailed information on each command, refer to the Linux manual pages.