SSH (Secure Shell) is a protocol used for secure communication between devices over unsecured networks. It provides encryption to ensure confidentiality, integrity, and authenticity. Here’s a detailed breakdown of its components and uses:
Components of SSH
ssh-keygen
: Creates authentication key pairs for password-less and secure SSH access.- SCP (Secure Copy Protocol): Facilitates secure file copying between hosts over a network.
- SFTP (Secure File Transfer Protocol): A secure alternative to FTP and FTPS for transferring files, leveraging SSH encryption.
Port and Accessibility
The default port for SSH servers is TCP 22, though custom ports can be configured for added security or specific application needs.
Key Features of SSH
- Remote System Management: Allows users to log in to remote computers and execute commands securely.
- File Transfers: Enables secure copying and sharing of files between systems using tools like SCP and SFTP.
- Secure Tunnels: Provides a method for tunneling other application protocols securely over a network, enhancing their security.
Basic SSH commands
SSH Commands
-
ssh
Connect to a remote server. -
ssh user@host
Connect to a specific device or IP as a specified user. -
ssh user@host -p [port]
Connect to a remote host using a specific port. -
ssh -i [keyfile] user@host
Connect to a remote host using an identity (private key) file. -
ssh user@host 'command'
Execute a command on the remote server. -
ssh user@host bash < script.sh
Execute a local script on the remote server during the session. -
ssh user@host 'command' > output.file
Execute a command remotely and save the output locally.
SSH Key Management
-
ssh-keygen
Generate SSH keys (follow prompts). -
ssh-keygen -F [ip/hostname]
Find an IP/hostname in~/.ssh/known_hosts
. -
ssh-keygen -R [ip/hostname]
Remove an IP/hostname from~/.ssh/known_hosts
. -
ssh-keygen -f [filename]
Specify the output file name when generating keys. -
ssh-keygen -y -f private.key > public.pub
Generate a public key from a private key. -
ssh-keygen -c -f ~/.ssh/id_rsa
Change the comment on a private key file. -
ssh-keygen -p -f ~/.ssh/id_rsa
Change the passphrase of a private key. -
ssh-keygen -t [keytype] -b [bits] -C "[comment]"
Generate a key with specific type, size, and comment.
SCP Commands (Secure Copy)
-
scp [source] [destination]
Copy files between local and remote servers. -
scp user@host:/file ./
Copy a file from remote to local. -
scp ./file user@host:/path/
Copy a file from local to remote. -
scp user1@host1:/file user2@host2:/path/
Copy a file directly between two remote servers. -
scp -r
Recursively copy entire directories. -
Options:
-C
: Compress data during transfer.-v
: Verbose output.-p
: Preserve file timestamps.-P [port]
: Specify the port for remote host.-B
: Batch mode, disables password prompts.
SFTP Commands (Secure File Transfer Protocol)
-
sftp [user@host]
Start an interactive SFTP session. -
Options:
-p
: Preserve timestamps.-P [port]
: Use a specific port.-r
: Recursively copy directories (no symlink traversal).
Leave a Reply