SSH to the remote server
This article demonstrates how to use to ssh
securely connect to a remote Linux server.
Securely access remote Linux servers using SSH (Secure Socket Shell)
SSH is the abbreviation of Secure Socket Shell. It is a protocol used to securely access remote Linux machines.
Once the SSH connection is established between your computer and the remote Linux machine, a shell is started on the remote Linux machine and you can access this shell on your computer. You can use this shell to run all the commands on the remote Linux machine like your local computer.
SSH protocol is very secure for accessing remote Linux machines and is commonly used by system and network administrators to maintain and configure remote Linux machines.
SSH uses a client-server architecture. It has a client-side component and a server-side component. People who want to access a remote Linux machine need to install an SSH client on their machine.
SSH client is a program to access a remote Linux machine. The person enters the remote Linux machine's information and credentials into the SSH client and if the details are valid, a secure SSH connection is initiated.
The server-side component runs on a remote Linux machine, which needs to have the SSH service installed, started, and running.
The SSH service continuously listens for incoming connections on a specific port (such as a server). If an SSH client initiates a connection, the SSH service responds with the protocol version it supports, and the two exchange identification data. Once the credentials are valid, the SSH connection is established.
There are many SSH tools available. OpenSSH is one of them, mainly used in Linux distributions. This tutorial will use OpenSSH for demonstration.
Install OpenSSH client in Linux
Many Linux distributions come with an SSH client already installed. In Linux, it is always a good idea to check if a program is already installed before installing it.
We check if it is already installed
by typing ssh
and pressing .Enterssh
ssh
The command displays its usage in the standard output. This means that the SSH client has been installed. If the SSH client is not installed, install it before continuing with this tutorial.
Type the following command to install OpenSSH client on your machine. It will ask you to enter the superuser password, provide the password to continue with the installation.
sudo apt-get install openssh-client
Windows users can use the well-known PuTTY
program as an SSH client.
Install OpenSSH server on the remote Linux machine
Before accessing a remote Linux machine, make sure that the OpenSSH server is installed on that machine. If not, make sure to install it.
To install the OpenSSH server on Linux, run the following command.
sudo apt-get install openssh-server
We try to install OpenSSH server in the image below, but the machine says that we already have OpenSSH server installed on our machine.
Start the OpenSSH server on the remote Linux machine
After successfully installing OpenSSH server on the remote Linux machine, we need to start the OpenSSH service to listen for incoming connections from SSH clients.
First, we sudo service ssh status
check the status of the OpenSSH service by typing . The output below indicates that the service is inactive.
We use sudo service ssh start
the command to start the OpenSSH service. This command starts ssh
the daemon running.
We use sudo service ssh status
the command to check the status of the service. The output shows that the service is now in 活动(运行)
status.
The remote Linux machine has the OpenSSH server installed and it is up and running. It is now ready to accept incoming connections from SSH clients.
Use ssh
command to access remote Linux machine
We create a new user on the remote Linux machine, which we will use for demonstration purposes in this tutorial. Using useradd
the command, we create a new user jiyik
.
We use passwd
the command to set the user's password jiyik
.
$ useradd jiyik
$ passwd jiyik
Enter New Unix password
Retype New Unix password
Now, we go into the machine where OpenSSH client is installed and try to jiyik
access the remote Linux machine using the newly created user.
SSH uses the following notation to log into a remote Linux machine.
ssh username@remotehostname
ssh username@remoteIPaddress
SSH will ask for the user's password delftstack
, enter the password and press Enter. After seeing the output below, you have successfully logged into the remote Linux machine.
$ ssh jiyik@localhost
For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.
Related Articles
How to decompress x.tar.xz format files under Linux
Publish Date:2025/04/08 Views:186 Category:OPERATING SYSTEM
-
A lot of software found today is in the tar.xz format, which is a lossless data compression file format that uses the LZMA compression algorithm. Like gzip and bzip2, it supports multiple file compression, but the convention is not to compr
Summary of vim common commands
Publish Date:2025/04/08 Views:115 Category:OPERATING SYSTEM
-
In Linux, the best editor should be vim. However, the complex commands behind vim's powerful functions also make us daunted. Of course, these commands do not need to be memorized by rote. As long as you practice using vim more, you can reme
Detailed explanation of command return value $? in Linux
Publish Date:2025/04/08 Views:58 Category:OPERATING SYSTEM
-
? is a special variable. This variable represents the return value of the previous command. That is to say, when we run certain commands, these commands will return a code after running. Generally, if the command is successfully run, the re
Common judgment formulas for Linux script shell
Publish Date:2025/04/08 Views:159 Category:OPERATING SYSTEM
-
In shell script programming, predicates are often used. There are two ways to use predicates, one is to use test, and the other is to use []. Let's take a look at how to use these two methods through two simple examples. Example 1 # test –
Shell script programming practice - specify a directory to delete files
Publish Date:2025/04/08 Views:98 Category:OPERATING SYSTEM
-
Usually, in Linux system we need to frequently delete some temporary files or junk files. If we delete them one by one manually, it will be quite troublesome. I have also been learning shell script programming recently, so I tried to write
Use of Linux command at - set time to execute command only once
Publish Date:2025/04/08 Views:158 Category:OPERATING SYSTEM
-
This article mainly involves a knowledge point, which is the atd service. Similar to this service is the crond service. The functions of these two services can be similar to the two functional functions of javascript. Those who have learned
Use of Linux command crontab - loop execution of set commands
Publish Date:2025/04/08 Views:170 Category:OPERATING SYSTEM
-
Compared with at , which executes a command only once, crontab, which we are going to talk about in this article, executes the set commands in a loop. Similarly, the use of crontab requires the support of the crond service. The service is s
Linux practice - regularly delete files under the directory
Publish Date:2025/04/08 Views:198 Category:OPERATING SYSTEM
-
Since we want to delete the files under the directory regularly, we need to use the Linux crontab command. And the content format of each work routine is also introduced in the format of each crontab work. Similarly, we need to use shell sc
How to use the Linux file remote copy command scp
Publish Date:2025/04/08 Views:151 Category:OPERATING SYSTEM
-
Scp copies files between two hosts over the network, and the data is encrypted during transmission. Its underlying layer uses ssh for data transmission. And it has the same authentication mechanism and the same security level as ssh. When u