Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the basic usage of openssh

2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "what is the basic use of openssh". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "what is the basic use of openssh"?

What is SSH?

To put it simply, SSH is a network protocol that is used for encrypted login between computers.

If a user logs in to another remote computer from the local computer using the SSH protocol, we can assume that the login is secure and that the password will not be disclosed even if intercepted halfway.

In the earliest days, Internet communications were all plaintext communications, and once intercepted, the content was undoubtedly exposed. In 1995, Finnish scholar Tatu Ylonen designed SSH protocol, which encrypts all login information, which has become a basic solution of Internet security. It has been rapidly promoted all over the world, and has become the standard configuration of Linux system.

It should be pointed out that SSH is just a protocol, and there are multiple implementations, both commercial and open source. The implementation of this paper is OpenSSH, which is free software and has a wide range of applications.

Install the package:

3 software packages are required for OpenSSH service

Openssh-4.3p2-24.el5.i386.rpm: contains the core files needed by the OpenSSH server and client

Openssh-clients-4.3p2-24.el5.i386.rpm:OpenSSH client package

Openssh-server-4.3p2-24.el5.i386.rpm:OpenSSH server software package

Second, the most basic usage

SSH is mainly used for remote login. Suppose you use root to log in to the remote host host, just one

A simple command will do.

$ssh root@host

Because the local user name is the same as the remote user name, the user name can be omitted when logging in.

$ssh host

The default port for SSH is 22, that is, your login request will be sent to port 22 of the remote host. Using the-p parameter, you can modify this port.

$ssh root@host-p 8099

The above command indicates that ssh is directly connected to port 8099 of the remote host.

Man-in-the-middle attack

The reason why SSH is secure is that it uses public key encryption.

The whole process goes like this:

(1) the remote host receives the login request from the user and sends its public key to the user.

(2) the user uses this public key to encrypt the login password and send it back.

(3) the remote host uses its own private key to decrypt the login password and allow the user to log in if the password is correct.

The process itself is secure, but there is a risk when it is implemented: if someone intercepts a login request and then pretends to be a remote host and sends the fake public key to the user, it is difficult for the user to tell the authenticity from the false. Because unlike the https protocol, the public key of the SSH protocol is not notarized by the Certificate Authority (CA), that is, it is signed by itself.

It is conceivable that if an attacker intervenes between the user and the remote host (such as in the public wifi area) and uses a fake public key to obtain the user's login password. Then log in to the remote host with this password, and the security mechanism of SSH will be gone. This risk is known as man-in-the-middle attack (Man-in-the-middle attack).

IV. Password login

If you are logged in to the other host for the first time, the following prompt will appear:

$ssh user@host

The authenticity of host 'host (12.18.429.21)' can't be established.

RSA key fingerprint is 98:2e:d7:e0:de:9f:ac:67:28:c2:42:2d:37:16:58:4d.

Are you sure you want to continue connecting (yes/no)?

What this means is that the authenticity of the host host cannot be confirmed, only its public key fingerprint is known. Do you want to continue to connect?

The so-called "public key fingerprint" means that the length of the public key is long (RSA algorithm is used here, which is as long as 1024 bits), so it is difficult to compare, so it is calculated by MD5 to turn it into a 128bit fingerprint. In the above example, it is 98:2e:d7:e0:de:9f:ac:67:28:c2:42:2d:37:16:58:4d, and it is much easier to compare.

A natural question is, how does the user know what the public key fingerprint of the remote host should be? The answer is that there is no good way, and the remote host must post a public key fingerprint on its own website so that users can check it themselves.

Suppose that after risk measurement, the user decides to accept the public key of the remote host.

Are you sure you want to continue connecting (yes/no)? Yes

A prompt appears indicating that the host host has been recognized.

Warning: Permanently added 'host,12.18.429.21' (RSA) to the list of known hosts.

A password is then asked for.

Password: (enter password)

If the password is correct, you can log in.

When the public key of the remote host is accepted, it is saved in the file $HOME/.ssh/known_hosts. The next time you connect to this host, the system will recognize that its public key has been saved locally, skip the warning section and prompt for the password directly.

Each SSH user has its own known_hosts file, and the system also has a file, usually / etc/ssh/ssh_known_hosts, that holds the public keys of remote hosts that can be trusted by all users.

V. Public key login

To log in with a password, you must enter a password every time, which is very troublesome. Fortunately, SSH also provides public key login, which eliminates the step of entering a password.

The so-called "public key login", the principle is very simple, is that the user stores his public key on the remote host. When logging in, the remote host sends a random string to the user, which is encrypted with his own private key and then sent back. The remote host uses the pre-stored public key for decryption, if successful, it proves that the user is trusted, directly allows login to the shell, and no longer requires a password.

This method requires that the user must provide his own public key. If there is no ready-made one, you can directly use ssh-keygen to generate one:

$ssh-keygen

After running the above command, the system will appear a series of prompts, you can enter all the way. One of the questions is whether to set a password (passphrase) on the private key. If you are worried about the security of the private key, you can set one here.

After running, in the $HOME/.ssh/ directory, two new files are generated: id_rsa.pub and id_rsa. The former is your public key and the latter is your private key.

Then enter the following command to transfer the public key to the remote host host:

$ssh-copy-id user@host

Well, if you log in again, you won't need to enter your password.

If it still doesn't work, open the / etc/ssh/sshd_config file on the remote host and check that the "#" comment in front of the following lines is removed.

RSAAuthentication yes

PubkeyAuthentication yes

AuthorizedKeysFile .ssh / authorized_keys

Then, restart the ssh service for the remote host.

/ / ubuntu system

Service ssh restart

/ / debian system

/ etc/init.d/ssh restart

VI. Authorized_keys file

The remote host saves the user's public key in the $HOME/.ssh/authorized_keys file in the user's home directory after login. The public key is a string, just append it to the end of the authorized_keys file.

Instead of using the ssh-copy-id command above, use the following command to explain the process of saving the public key:

$ssh user@host 'mkdir-p. Ssh & & cat > > .ssh / authorized_keys'

< ~/.ssh/id_rsa.pub 这条命令由多个语句组成,依次分解开来看: (1)"$ ssh user@host",表示登录远程主机; (2)单引号中的mkdir .ssh && cat >

> .ssh / authorized_keys, which indicates the command executed on the remote shell after login:

(3) the purpose of "$mkdir-p. Ssh" is to create a .ssh directory if the .ssh directory in the user's home directory does not exist.

(4) the function of 'cat > > .ssh / authorized_keys' < ~ / .ssh/id_rsa.pub is to append the local public key file ~ / .ssh/id_rsa.pub to the end of the remote file authorized_keys.

After writing to the authorized_keys file, the setup of the public key login is complete.

Trinity's way of hacking into the power station in the movie Matrix: reinstall is based on the SSH CRC-32 vulnerability.

SSH is a remote access encryption protocol in which there is an integer overflow in the CRC32 compensation attack detection code that allows remote attackers to write values anywhere in memory.

HostKey / etc/ssh/ssh_host_key

Set up the file that contains the private key of the computer

# HostKey / etc/ssh/ssh_host_rsa_key # RSA private key used by SSH version 2

# HostKey / etc/ssh/ssh_host_dsa_key # DSA private key used by SSH version 2

# remember what we talked about in the SSH online process of the host, this is Host Key. SyslogFacility AUTHPRIV

# when someone logs in to the system using SSH, SSH will record the information, and the type of information to be recorded is AUTHPRIV.

At this point, I believe you have a deeper understanding of "what is the basic use of openssh". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report