SSH - Secure Shell

Screenshot about the usage of SSH in Linux.

Description

SSH (Secure Shell) is an encrypted protocol that allows secure access to a remote system through the command line. It is commonly used to manage Linux servers, execute remote commands, and securely transfer files.

What is SSH and what is it used for

SSH replaces insecure protocols such as telnet and rlogin, providing authentication and encryption of exchanged data. It typically operates on port 22.

Basic connection

The general syntax of the SSH command is:

ssh username@hostname

Example:

ssh [email protected]

On the first connection, SSH will ask you to confirm the remote server’s key and then request the password of the specified user.

Authentication with public key

To avoid typing the password each time and to improve security, SSH can use a pair of keys (public and private).

  1. Generate a key pair on your computer:

ssh-keygen -t ed25519 -C "[email protected]"

  1. Send the public key to the remote server:

ssh-copy-id username@hostname

After that, you can log in without a password, since authentication will occur through your locally stored private key.

SSH configuration file

To simplify usage, you can create or edit the ~/.ssh/config file and define aliases for frequently used servers:

Host my-server
    HostName 192.168.1.10
    User root
    IdentityFile ~/.ssh/id_ed25519

From that point, you can connect simply by typing:

ssh my-server

File transfer with SSH

You can copy files between your local system and a remote server using scp or sftp.

Examples:

scp file.txt [email protected]:/home/user/

scp [email protected]:/var/log/syslog ./

Or open an interactive SFTP session:

sftp [email protected]

Port forwarding (tunneling)

SSH allows the creation of encrypted tunnels between local and remote ports, useful for accessing internal services that are not publicly exposed.

Example: forward local port 8080 to port 80 on a remote server:

ssh -L 8080:localhost:80 user@remote_host

You can now open http://localhost:8080 in your browser and access the remote service as if it were local.

Useful commands

Common issues

Conclusion

SSH is an essential tool for anyone working with remote servers or networks. Using it correctly and securely (through keys, configurations, and proper permissions) is crucial to maintaining the integrity of your system and data.

SLD-Server

Details

Name: SSH - Secure Shell

Categories: linux, server, network

Updated: 10/11/2025

Autor: Simone Cusano

Author Website: https://sld-server.org


Created on: 10/11/2025.