[ TechDocsCove ]  TechDocsCove en   ↩︎

# Understanding SSH and Its Usage in Linux

linux   remote access   shell   system administration  

translations: [ es/Español ] · [ fr/Français ] · [ de/Deutsch ]


Table of contents


Secure Shell (SSH) is a powerful tool for accessing remote machines securely. It provides a secure channel over an unsecured network, offering encrypted communication between the client and the server. Here’s a comprehensive guide to utilizing SSH on Linux, covering connection, known_hosts, and essential commands.

Connecting via SSH

Syntax

To initiate an SSH connection, use the following syntax:

ssh username@hostname

Replace username with your username on the remote machine and hostname with the IP address or domain name of the server.

Example

Let’s say your username on the remote machine is user and the server’s IP address is 192.168.1.100. To connect, use:

ssh user@192.168.1.100

Password-based Authentication

Upon the first connection, SSH prompts for the user’s password. It’s worth noting that passwords are not visible when typed, providing an extra layer of security. Subsequent logins might not ask for the password if SSH keys are set up.

SSH Keys and Key-based Authentication

SSH keys enhance security by replacing passwords with cryptographic keys. The steps to generate and use SSH keys are:

  1. Generate SSH Key Pair:

    ssh-keygen -t rsa -b 4096
    

    This command generates an RSA key pair (id_rsa and id_rsa.pub files) in the ~/.ssh/ directory by default.

  2. Copy Public Key to Remote Machine: Use ssh-copy-id to add the public key to the remote machine’s authorized_keys file:

    ssh-copy-id user@hostname
    
  3. Key-based Authentication: Once the key is copied, SSH won’t prompt for passwords during subsequent logins.

Managing known_hosts

What is known_hosts?

The known_hosts file stores host keys of remote servers. When connecting to a server, SSH checks this file to verify the server’s identity. If the server’s key changes, SSH displays a warning.

Handling known_hosts Issues

Sometimes, SSH might throw warnings due to host key changes, IP changes, or when connecting to a new server. To resolve these issues:

Essential SSH Commands

ssh-agent

The ssh-agent is a program to hold private keys used for public key authentication. It allows keys to be used without re-entering passphrases.

eval $(ssh-agent)
ssh-add ~/.ssh/id_rsa

scp - Secure Copy

scp securely transfers files between a local and a remote host.

scp /path/to/local/file user@hostname:/path/to/remote/directory

sshfs - SSH File System

sshfs enables mounting a remote filesystem over SSH.

sshfs user@hostname:/remote/directory /local/mount/point

Utilizing SSH on Linux provides a secure and versatile way to interact with remote systems. By understanding its fundamentals and commands, users can navigate and manage remote machines efficiently and securely.



Created on: Jan 7, 2024


Email shareIcon for sharing via email    Reddit shareIcon for sharing via Reddit    X shareIcon for sharing via X    Telegram shareIcon for sharing via Telegram    WhatsApp shareIcon for sharing via WhatsApp    Facebook shareIcon for sharing via Facebook    LinkedIn shareIcon for sharing via LinkedIn



Discover More within this Subject: