ssh Command: Tutorial & Examples

Connect to a remote host using the Secure Shell (SSH) protocol

The ssh command is a Linux utility that allows you to securely connect to a remote server using the Secure Shell (SSH) protocol. It is commonly used to remotely access and manage servers, as well as to securely transfer files between systems.

To use the ssh command, you will need to specify the username and the IP address or domain name of the remote server that you want to connect to. For example, to connect to a remote server with the IP address 123.456.789.101 using the username user, you might use the following command:

ssh user@123.456.789.101

This will normally prompt you for your password, and if the login is successful, you will be connected to the remote server and will be able to run commands and perform other tasks as if you were logged in directly on the server.

It is generally considered more secure to use SSH keys instead of passwords for authentication when connecting to a remote server. SSH keys are cryptographic keys that are used to authenticate SSH connections. They are more secure than passwords because they are much harder to crack and are not vulnerable to common types of attacks such as dictionary or brute force attacks.

To use SSH keys for authentication, you will need to generate a public and private key pair on your local machine using the ssh-keygen command. You will then need to copy the public key to the remote server and configure it to allow you to log in using the private key.

To execute a command on a remote machine, you can use the -t option to force ssh to allocate a pseudo-terminal and pass the command as an argument. For example, to list the contents of the home directory on the remote server, you might use the following command:

ssh user@123.456.789.101 -t "ls ~"

This will execute the ls command on the remote server and display the output on the local terminal.

ssh is a powerful and flexible tool that is widely used to remotely access and manage servers. It is available on most Linux distributions and is commonly used in combination with other command-line tools to automate tasks and manage large numbers of servers.

Except where otherwise noted, content on this site is licensed under a CC BY-SA 4.0 license CC BY SA