🔐

Essential SSH Skills and Techniques

Aug 8, 2024

SSH Crash Course Notes

Introduction to SSH

  • SSH stands for Secure Shell.
  • It is a protocol used for secure communication between computers.
  • Essential for web development, especially when transitioning from FTP.
  • This course will cover SSH basics, usage, and key generation.

Overview of SSH Functionality

  • Allows for:
    • Creating files on remote computers
    • Running and installing programs
    • Deploying web applications
  • SSH is encrypted, providing security compared to protocols like Telnet.
  • Commonly used in remote command line or terminal sessions.

Authentication Methods

  1. Password Authentication
    • Default method: username/password.
    • Example command: ssh user@hostname
  2. SSH Keys
    • Recommended for better security.
    • Involves generating a pair of public and private keys.
  3. Host-Based Authentication
    • Uses a known hosts file to manage allowable connections.

Generating SSH Keys

  • Use the command: ssh-keygen
    • Default location: ~/.ssh/
    • Files generated:
      • Private Key: id_rsa
      • Public Key: id_rsa.pub
  • Public key must be added to the server in the ~/.ssh/authorized_keys file.

Logging into a Local Server

  • Example command for logging in: ssh [email protected]
  • First-time login prompts to accept the unknown host.
  • Upon success, the terminal displays a welcome message.

Managing Files on Remote Servers

  • Commands in SSH:
    • ls to list files
    • cd to change directories
    • mkdir to create directories
    • touch to create files
    • rm -rf to remove files/directories.

Installing Software on a Remote Server

  • Install Apache as an example:
    • Command: sudo apt install apache2 -y
  • Confirm installation by accessing the server's IP address in a web browser.

Setting Up SSH Keys on a Remote DigitalOcean Server

  1. Create a Droplet on DigitalOcean:
    • Choose a server package and set up SSH keys.
  2. Log in as Root User:
    • Use SSH keys for passwordless entry.
  3. Create a New User:
    • Example: adduser username
    • Grant sudo privileges: usermod -aG sudo username

Configuring SSH Key Permissions

  • SSH keys must be placed in ~/.ssh/authorized_keys for each user.
  • Change ownership of .ssh directory if necessary.
    • Command: sudo chown -R username:username /home/username/.ssh

Setting Up SSH with GitHub

  1. Generate a new SSH key specifically for GitHub:
    • Command: ssh-keygen -t rsa -f ~/.ssh/id_rsa_github
  2. Add the public key to GitHub under SSH and GPG settings.
  3. Clone a repository using the SSH command to confirm functionality.

Additional Commands

  • To copy files from local to remote:
    • Use scp command.
  • Managing the SSH agent:
    • Start SSH agent using eval $(ssh-agent -s).
    • Add key using ssh-add ~/.ssh/id_rsa_github.

Conclusion

  • This crash course provided insights into using SSH, setting up keys, and managing servers.
  • Aimed at beginners and those transitioning to remote server management.
  • Additional practice with commands and configurations is encouraged for better understanding.