SSH is a cryptographic network protocol used for an encrypted connection between a client and a server. OpenSSH client is the most widely used client.
The following requirements must be met to be able to login into a remote machine via SSH:
The basic syntax of the ssh command is as follows:
To use the ssh command, open your Terminal and type ssh followed by the remote hostname:
When you connect to a remote machine through SSH for the first time, you will see a message:
Each host has a unique fingerprint that is stored in the ~/.ssh/known_hosts file.
Type yes to store the remote fingerprint, and you’ll be prompted to enter your password.
Once you enter the password, you will be logged into the remote machine.
When the username is not given, the ssh command uses the current system login name.
To log in as a different user, specify the username and the host in the following format:
By default, when no port is given, the SSH client will try to connect to the remote server on port 22.
You can change the default SSH port to add an extra layer of security to the server by reducing the risk of automated attacks. To connect on a non-default port, use the -p option to specify the port:
If you are experiencing issues from authentication or connection, try the -v option to print debugging messages:
You can try a higher of verbosity with -vv, -vvv.
For a complete list of options read the manual page by typing man ssh in your terminal.
In case you are connecting to multiple remote systems over SSH. It is better to use the OpenSSH client with configuration file ~/.ssh/config.
In this file, you can store different SSH options for each remote machine you want to connect.
A sample SSH config is shown below:
Host dev HostName dev.particle.com User quark Port 1234
When you invoke the ssh client by typing
the command will read the ~/.ssh/config file and use the connection details specified for the dev host. In this example, ssh dev is equivalent to the following: