Cloud Knowledge

Your Go-To Hub for Cloud Solutions & Insights

Advertisement

Mastering SSH: Essential Commands for Remote Server Management

Mastering SSH: Essential Commands for Remote Server Management

SSH Configurations and Options Reference

Key Configuration Files and Their Purpose
  • man ssh_config: Access the manual for OpenSSH client configuration. It lists all configurable OpenSSH parameters.
  • cat /etc/ssh/ssh_config | less: View the system-wide OpenSSH client configuration file.
  • cat /etc/ssh/sshd_config | less: View the system-wide OpenSSH server configuration file. (The “d” in sshd refers to the server daemon.)
  • cat ~/.ssh/config | less: View the user-specific SSH client configuration file.
  • cat ~/.ssh/id_{type} | less: View private SSH keys. Replace {type} with rsa, ed25519, dsa, or ecdsa.
  • cat ~/.ssh/id_{type}.pub | less: View public SSH keys. Replace {type} as above.
  • cat ~/.ssh/known_hosts | less: View the list of hosts your SSH client has connected to.
  • cat ~/.ssh/authorized_keys | less: View the list of public keys authorized to log in to a specific machine.
Working with ssh-agent
  • ssh-agent: Manages private keys for public key authentication.
  • ssh-agent -E {fingerprint_hash}: Specify the hash algorithm for displaying key fingerprints. Options:
    • sha256 (default)
    • md5
  • ssh-agent -t {lifetime}: Set a maximum lifetime for private keys. Examples of lifetime values:
    • 600 → 600 seconds (10 minutes)
    • 23m → 23 minutes
    • 1h45 → 1 hour 45 minutes
Managing Keys with ssh-add
  • ssh-add: Add private SSH keys to the ssh-agent.
  • ssh-add -l: List private keys cached by ssh-agent.
  • ssh-add -t {lifetime}: Set a specific lifetime for cached keys.
  • ssh-add -L: Display the public key parameters for all cached private keys.
  • ssh-add -D: Remove all cached private keys.

Setting Up SSH Key Authentication

  • ssh-copy-id user@server: Copy SSH keys to a remote server for a specific user.
  • ssh-copy-id server1: Copy SSH keys to an alias (e.g., server1) using the default login.
  • ssh-copy-id -i ~/.ssh/id_rsa.pub user@server: Copy a specific SSH public key to a server.

Remote Server Management Commands for SSH

Once connected to a remote server via SSH, many commands you use are standard Unix/Linux commands. Below is a quick reference:

Basic Commands
  • cd: Change the current working directory.
  • pwd: Display the current working directory.
File and Directory Management
  • ls: List files and directories in the current directory.
  • mkdir {directory_name}: Create a new directory.
  • mv {source} {destination}: Move or rename files/directories.
  • touch {file_name}: Create a new file or update the timestamp of an existing file.
  • nano {file_name}: Edit a file in the terminal using Nano.
  • vim {file_name}: Edit a file in the terminal using Vim.
Process Management
  • ps: List running processes.
  • kill {PID}: Terminate a running process by its Process ID (PID).
  • top: Monitor system resources and running processes in real-time.
Viewing File Content
  • tail {file_name}: View the last few lines of a file (default: 10 lines).
Ending the SSH Session
  • exit: Close the SSH session and return to your local machine.

Conclusion

SSH is a powerful tool for managing remote servers, offering secure access and control over various systems. By mastering the essential commands and configurations, you can efficiently navigate, manage files, monitor processes, and enhance server security. Whether you’re editing configuration files, managing SSH keys, or performing routine maintenance, understanding these commands empowers you to work effectively in a remote server environment.

With these tools at your disposal, you’re well-equipped to streamline your workflows and tackle any server management task with confidence. Start exploring, practicing, and unlocking the full potential of SSH!

Leave a Reply

Your email address will not be published. Required fields are marked *