You can SSH using the command line with a few requirements and steps. This post details everything you should know.
Understanding SSH
The SSH command is available in the Linux system and is handy when connecting to a remote machine. With the SSH connection, you can transfer files, tunnel applications, execute commands on the remote machine, etc.
When using SSH on the Linux command line, you will interact with the remote machine only after you connect to it. Moreover, the remote and client machine must have the “openssh” installed and enabled to establish the connection.
How to SSH from the Linux Command Line
Before you can create the SSH connection, you must have the “openssh” installed on your server and the client. Let’s begin with getting the remote machine ready for the connection.
Update the apt repository before you can install the “openssh”.
After the update, you must install the “openssh-server” on the remote machine. Only when the server has the “openssh-server” can it accept a remote connection that is established on the client machine. The “openssh” relies on the configurations that are defined in the /etc/ssh/sshd_config.
Run the following command to install the “openssh-server”:
Once installed, check the “ssh” status to ensure if it is active (running).
If the status is not active, you can start it by running the following command:
Check the IP of the remote machine. Use the “ip a” command and get the IP that is associated with your network interface. In this case, we use the wireless interface “wlo1”.
On the client machine, you must install the “openssh-client” to use it to create the connection to the remote machine.
Similar to the remote machine, start by updating the apt repository.
Install the “openssh-client” by executing the following command:
Once you installed the “openssh-client” and the “openssh-server”, you are ready to establish the connection using SSH. To establish the connection, open your terminal on the client machine and connect to the IP of the remote server.
Our remote machine has its IP as 192.168.137.201. Thus, we connect to it by running the following SSH command:
You must specify the hostname of the remote machine. Linuxhint is the hostname for our target remote server.
You will get prompted to authenticate the connection by selecting whether to continue. On the prompt that appears, type “yes” and press the enter key. You will see a prompt which confirms that the IP address of the remote machine has been added as one of the known hosts.
The last step is to type the password of the remote machine in the login prompt that appears on the terminal.
Once the entered password matches to the remote host’s, you have successfully used the SSH to connect to a remote machine using the Linux command line. That’s it!
Conclusion
SSH offers a secure way of connecting to a remote machine from a client machine. To use SSH on the Linux command line, install the “openssh-client” on the client machine and the “openssh-server” on the remote machine. Once installed, enable “ssh” on both machines. Lastly, execute the “ssh” command with the hostname and the IP address of the remote machine, and enter the password to connect to it.