Home Operation and Maintenance CentOS Detailed explanation of CentOS SSH installation and configuration

Detailed explanation of CentOS SSH installation and configuration

Nov 13, 2020 pm 03:14 PM
centos

The following column centos tutorial will introduce CentOS SSH installation and configuration to you. I hope it will be helpful to friends in need!

CentOS SSH installation and configuration

SSH is the abbreviation of Secure Shell, formulated by the IETF Network Working Group; SSH is built on the application layer and security protocols based on the transport layer.

Traditional network service programs, such as FTP, POP and Telnet, are inherently unsafe; because they transmit data, user accounts and user passwords in plain text on the network, they are easily vulnerable to man-in-the-middle (man- in-the-middle) attack. It means that there is another person or machine pretending to be a real server to receive the data sent by the user to the server, and then pretending to be the user to send the data to the real server.

SSH is currently a more reliable protocol designed to provide security for remote login sessions and other network services. Using the SSH protocol can effectively prevent information leakage during remote management. All transmitted data can be encrypted through SSH, and DNS spoofing and IP spoofing can also be prevented.

Install SSH:

yum install ssh
Copy after login

Start SSH:

service sshd start
Copy after login

Set up to run on boot:

chkconfig sshd on
Copy after login

Generally, CentOS has OpenSSH installed by default, even if you minimize it The same goes for installation.

SSH configuration:

1. Modify vi /etc/ssh/sshd_config, remove the parameter comments to be modified according to the template and modify the parameter value:

Port 22 specifies SSH connection Port number, it is not recommended to use the default port 22 for security reasons

Protocol 2,1 allows SSH1 and SSH2 connections, it is recommended to set it to Protocol 2

Other parameters can be adjusted according to your own needs. For details on the configuration method, see: man ssh_config

2. Modify hosts.deny and add a line at the end:

sshd:All
Copy after login
Copy after login

3. Modify hosts.allow and add a line at the end:

sshd:All
Copy after login
Copy after login

If you want to install an IP that can restrict access, set it as follows:

sshd:192.168.0.101
sshd:192.168.0.102
Copy after login

The above configuration means that only servers 101 and 102 are allowed to make SSH connections

4. Start SSH

/etc/init.d/sshd start
Copy after login

At this point SSH can be connected

Enter the connection IP

Configure related parameters

Select utf-8 to support Chinese display

Automatically enter the login user root

After entering the user name, you can connect to the server

But currently our SSH connection still requires a password. The following will introduce how to use a key to connect, eliminating the trouble of entering a password:

1. Produce the key on the managed machine

[root@localhost ~]# mkdir /root/.ssh
[root@localhost ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):   ##直接回车默认路径
Enter passphrase (empty for no passphrase):                ##输入密码短语
Enter same passphrase again:                               ##重复密码短语
Your identification has been saved in /root/.ssh/id_rsa.   ##如果在这里报错是因为SeLinux引起的按照Policy:yum install selinux-policy
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
aa:76:71:1e:51:fe:3b:4c:51:30:b2:90:55:e9:58:7c root@localhost.localdomain
The key's randomart image is:
+--[ RSA 2048]----+
|        .ooo+o   |
|        ...o+.E  |
|         o.+ o   |
|        . o o    |
|        S. . .   |
|      ..o   o    |
|      .+ . o .   |
|    ... .   +    |
|   ...       .   |
+-----------------+
Copy after login

2. Produce the key for putty

Open puttygen. If you don’t have this program, you can download it from the putty official website.

The following picture will appear after clicking the Generate button. Keep moving the mouse in the red box until the key generation is completed

The big red box above is the public key we generated. This public key is used to place on the managed server, and the private key is placed on your own machine.

Key comment is a remark information. If it is an enterprise environment, there will be many public keys on one machine. In order to identify them, a comment will generally be defined according to each person's own.

You can use your email or work ID, enter Key comment to copy the public key first, and click Saved public Key and Saved Private Key to save the two keys

Then open the key agent tool pageant. exe (can also be downloaded from putty's official website), using pageant.exe has a great advantage. If you also need to use other tools of putty, then they can share the key verification without having to set the key repeatedly.

Right-click the pageant.exe icon on the taskbar and select view keys to open the following window.

Click Add key to add the private key you just saved.

3. Managed machine key deployment

Copy the id_rsa.pub just produced on the managed machine into authrized.keys

[root@localhost .ssh]# cp id_rsa.pub authrized.keys[root@localhost .ssh]# chmod 600 authrized.keys      ##这一步是必须的,否则连接不上
Copy after login

Modify vi /root/.ssh/ authrized.keys Delete the original key and add the key produced by puttygen.exe (that is, the public key copied earlier)

sh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAh+gDpVSNIwBHZvmHS240AoueNHIgDHhczQ/fhiN/IdAQVdh7Ovw2pnJ4sd6so0kqCizsU7FOu2rvaK7vHC3QrrYmeqn94V595pYGLnMCbtEd7ONew47TU8wjtdldbc7liEmkTVIdkCbbrzQa372/u2LSjkldu2BUiXkevlnGNUc= hellwen.wu~~~~
Copy after login

Save and exit.

4. Open putty to log in

Pay attention to the red part in the picture above. If you often connect to this machine, it is recommended to enter the IP and configure it, then enter the identification name in Saved Sessions and click Save button so that the server's connection configuration is permanently retained in the list box.

The above is the detailed content of Detailed explanation of CentOS SSH installation and configuration. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to optimize CentOS HDFS configuration How to optimize CentOS HDFS configuration Apr 14, 2025 pm 07:15 PM

Improve HDFS performance on CentOS: A comprehensive optimization guide to optimize HDFS (Hadoop distributed file system) on CentOS requires comprehensive consideration of hardware, system configuration and network settings. This article provides a series of optimization strategies to help you improve HDFS performance. 1. Hardware upgrade and selection resource expansion: Increase the CPU, memory and storage capacity of the server as much as possible. High-performance hardware: adopts high-performance network cards and switches to improve network throughput. 2. System configuration fine-tuning kernel parameter adjustment: Modify /etc/sysctl.conf file to optimize kernel parameters such as TCP connection number, file handle number and memory management. For example, adjust TCP connection status and buffer size

What are the backup methods for GitLab on CentOS What are the backup methods for GitLab on CentOS Apr 14, 2025 pm 05:33 PM

Backup and Recovery Policy of GitLab under CentOS System In order to ensure data security and recoverability, GitLab on CentOS provides a variety of backup methods. This article will introduce several common backup methods, configuration parameters and recovery processes in detail to help you establish a complete GitLab backup and recovery strategy. 1. Manual backup Use the gitlab-rakegitlab:backup:create command to execute manual backup. This command backs up key information such as GitLab repository, database, users, user groups, keys, and permissions. The default backup file is stored in the /var/opt/gitlab/backups directory. You can modify /etc/gitlab

Centos stops maintenance 2024 Centos stops maintenance 2024 Apr 14, 2025 pm 08:39 PM

CentOS will be shut down in 2024 because its upstream distribution, RHEL 8, has been shut down. This shutdown will affect the CentOS 8 system, preventing it from continuing to receive updates. Users should plan for migration, and recommended options include CentOS Stream, AlmaLinux, and Rocky Linux to keep the system safe and stable.

How to check CentOS HDFS configuration How to check CentOS HDFS configuration Apr 14, 2025 pm 07:21 PM

Complete Guide to Checking HDFS Configuration in CentOS Systems This article will guide you how to effectively check the configuration and running status of HDFS on CentOS systems. The following steps will help you fully understand the setup and operation of HDFS. Verify Hadoop environment variable: First, make sure the Hadoop environment variable is set correctly. In the terminal, execute the following command to verify that Hadoop is installed and configured correctly: hadoopversion Check HDFS configuration file: The core configuration file of HDFS is located in the /etc/hadoop/conf/ directory, where core-site.xml and hdfs-site.xml are crucial. use

What is the CentOS MongoDB backup strategy? What is the CentOS MongoDB backup strategy? Apr 14, 2025 pm 04:51 PM

Detailed explanation of MongoDB efficient backup strategy under CentOS system This article will introduce in detail the various strategies for implementing MongoDB backup on CentOS system to ensure data security and business continuity. We will cover manual backups, timed backups, automated script backups, and backup methods in Docker container environments, and provide best practices for backup file management. Manual backup: Use the mongodump command to perform manual full backup, for example: mongodump-hlocalhost:27017-u username-p password-d database name-o/backup directory This command will export the data and metadata of the specified database to the specified backup directory.

What steps are required to configure CentOS in HDFS What steps are required to configure CentOS in HDFS Apr 14, 2025 pm 06:42 PM

Building a Hadoop Distributed File System (HDFS) on a CentOS system requires multiple steps. This article provides a brief configuration guide. 1. Prepare to install JDK in the early stage: Install JavaDevelopmentKit (JDK) on all nodes, and the version must be compatible with Hadoop. The installation package can be downloaded from the Oracle official website. Environment variable configuration: Edit /etc/profile file, set Java and Hadoop environment variables, so that the system can find the installation path of JDK and Hadoop. 2. Security configuration: SSH password-free login to generate SSH key: Use the ssh-keygen command on each node

Centos shutdown command line Centos shutdown command line Apr 14, 2025 pm 09:12 PM

The CentOS shutdown command is shutdown, and the syntax is shutdown [Options] Time [Information]. Options include: -h Stop the system immediately; -P Turn off the power after shutdown; -r restart; -t Waiting time. Times can be specified as immediate (now), minutes ( minutes), or a specific time (hh:mm). Added information can be displayed in system messages.

Centos install mysql Centos install mysql Apr 14, 2025 pm 08:09 PM

Installing MySQL on CentOS involves the following steps: Adding the appropriate MySQL yum source. Execute the yum install mysql-server command to install the MySQL server. Use the mysql_secure_installation command to make security settings, such as setting the root user password. Customize the MySQL configuration file as needed. Tune MySQL parameters and optimize databases for performance.

See all articles