Connect to Remote

LinuxLinuxBeginner
Practice Now

Introduction

In this lab, you will learn how to use the Linux ssh and telnet commands to remotely connect to and manage other Linux systems. These commands are powerful tools for system administrators and network engineers, as they allow you to perform a wide range of tasks remotely and securely.

Achievements

  • ssh - Secure Shell Connection Tool
  • telnet - Unencrypted Connection Tool

Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("`Linux`")) -.-> linux/PackagesandSoftwaresGroup(["`Packages and Softwares`"]) linux(("`Linux`")) -.-> linux/BasicFileOperationsGroup(["`Basic File Operations`"]) linux(("`Linux`")) -.-> linux/UserandGroupManagementGroup(["`User and Group Management`"]) linux(("`Linux`")) -.-> linux/RemoteAccessandNetworkingGroup(["`Remote Access and Networking`"]) shell(("`Shell`")) -.-> shell/BasicSyntaxandStructureGroup(["`Basic Syntax and Structure`"]) shell(("`Shell`")) -.-> shell/ControlFlowGroup(["`Control Flow`"]) shell(("`Shell`")) -.-> shell/SystemInteractionandConfigurationGroup(["`System Interaction and Configuration`"]) linux/PackagesandSoftwaresGroup -.-> linux/apt("`Package Handling`") linux/BasicFileOperationsGroup -.-> linux/ls("`Content Listing`") linux/UserandGroupManagementGroup -.-> linux/passwd("`Password Changing`") linux/UserandGroupManagementGroup -.-> linux/sudo("`Privilege Granting`") linux/RemoteAccessandNetworkingGroup -.-> linux/ssh("`Secure Connecting`") linux/RemoteAccessandNetworkingGroup -.-> linux/telnet("`Network Connecting`") linux/UserandGroupManagementGroup -.-> linux/set("`Shell Setting`") shell/BasicSyntaxandStructureGroup -.-> shell/comments("`Comments`") shell/BasicSyntaxandStructureGroup -.-> shell/quoting("`Quoting Mechanisms`") shell/ControlFlowGroup -.-> shell/for_loops("`For Loops`") shell/SystemInteractionandConfigurationGroup -.-> shell/shell_options("`Shell Options and Attributes`") subgraph Lab Skills linux/apt -.-> lab-34{{"`Connect to Remote`"}} linux/ls -.-> lab-34{{"`Connect to Remote`"}} linux/passwd -.-> lab-34{{"`Connect to Remote`"}} linux/sudo -.-> lab-34{{"`Connect to Remote`"}} linux/ssh -.-> lab-34{{"`Connect to Remote`"}} linux/telnet -.-> lab-34{{"`Connect to Remote`"}} linux/set -.-> lab-34{{"`Connect to Remote`"}} shell/comments -.-> lab-34{{"`Connect to Remote`"}} shell/quoting -.-> lab-34{{"`Connect to Remote`"}} shell/for_loops -.-> lab-34{{"`Connect to Remote`"}} shell/shell_options -.-> lab-34{{"`Connect to Remote`"}} end

Connecting to a Remote System Using SSH

The ssh command is used to securely connect to a remote system using the SSH (Secure Shell) protocol. To connect to a remote system, you will need to know the IP address or hostname of the system, as well as a valid username and password for an account on the system.

Here is an example of how to use the ssh command to connect to a remote system:

## Please set a password for labex user first.
sudo passwd labex

## The SSH default port is 22, you do not need to specify it.
ssh labex@127.0.0.1

In this example, user is the username and 127.0.0.1 is the IP address of the remote system(this example use labex user and local address).

Once you have connected to the remote system, you will be prompted to enter yes to confirm the connection and enter the labex user password. After you enter your password, you will be logged in to the remote system and will be able to run commands and manage the system just as if you were physically logged in to the system.

Executing Commands on a Remote System

Once you are logged in to a remote system using ssh, you can execute commands on the remote system just as if you were physically logged in to the system.

Here is an example of how to use ssh to execute a command on a remote system:

ssh labex@127.0.0.1 'ls -l'

In this example, the command ls -l is executed on the remote system with IP address 127.0.0.1 as the user labex.

You can also use a -t option to force pseudo-tty allocation, which allows you to run commands that require user input.

ssh -t labex@127.0.0.1 'sudo apt-get update'

Connecting to a Remote System Using Telnet

The telnet command is used to connect to a remote system using the Telnet protocol. Telnet is a plaintext protocol, which means that all data sent and received over a Telnet connection is unencrypted and can be read by anyone who intercepts the connection.

Here is an example of how to use the telnet command to connect to a remote system:

telnet 127.0.0.1

This Connection will refused, because the telnet service is not enabled by default in our lab environment.

In this example, 127.0.0.1 is the IP address of the remote system.

Once you have connected to the remote system, you will be prompted to enter a username and password. After you enter the correct credentials, you will be logged in to the remote system and will be able to run commands and manage the system just as if you were physically logged in to the system.

We suggest you to use ssh instead of telnet to connect to a remote system.

Summary

In this lab, you have learned how to use the ssh and telnet commands to remotely connect to and manage other Linux systems. You have learned how to connect to a remote system using SSH, how to execute commands on a remote system using ssh, and how to connect to a remote system using Telnet. Keep in mind that Telnet is a plaintext protocol and all data sent and received over a Telnet connection is unencrypted and can be read by anyone who intercepts the connection.

Other Linux Tutorials you may like