Esta página ainda não está disponível no idioma selecionado. Estamos trabalhando para adicionar mais opções de idiomas. Agradecemos sua compreensão.

Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive
Help Center/ Elastic Cloud Server/ Best Practices/ Securing an ECS/ Enhancing Security for SSH Logins to Linux ECSs

Enhancing Security for SSH Logins to Linux ECSs

Updated on 2024-11-04 GMT+08:00

Linux ECSs are generally logged in using SSH. How can I ensure login security for password-authenticated Linux ECSs? This section uses CentOS 7.6 as an example to describe how to enhance security for SSH logins.

Table 1 ECS configurations

Parameter

Example Value

Name

ecs-f5a2

OS

CentOS 7.6 64bit

EIP

119.3.xxx.x

Login mode

Password

Changing the Default Login Port

  1. Remotely log in to the ECS using its password through SSH. For details, see Login Using an SSH Password.
  2. Run the following command to change the default port for SSH logins, for example, to 5000:

    vim /etc/ssh/sshd_config

    Press i to enter insert mode. In line 17, delete the comment character (#) and change the port number to 5000.

    Figure 1 Before the change
    Figure 2 After the change
  3. Press Esc and enter :wq to save the changes and exit.

Adding a Firewall Rule to Open a Specified Port

CentOS 7 series use the fireware firewall rather than iptables by default. Perform the operations described in this section only if Iptables has been installed on your ECS to open port 5000 for SSH logins.

  1. Run the following command to check whether Iptables has been installed:

    service iptables status

    • If information similar to the following is displayed, Iptables has not been installed. In such a case, skip this section and proceed with Adding a Security Group Rule.

    • If information similar to the following is displayed, Iptables has been installed, and it is in active state. Then, go to step 2.

  2. Run the following command to add an Iptables rule to open port 5000:

    iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 5000 -j ACCEPT

  3. Run the following command to check whether port 5000 is contained in the existing Iptables rules:

    iptables -L -n

Adding a Security Group Rule

By default, port 22 is enabled in the inbound direction of a security group. After changing the SSH login port on your ECS to port 5000, add a rule for port 5000 to the security group.

  1. Log in to the management console.
  2. Under Compute, click Elastic Cloud Server. The ECS console is displayed.
  3. Click the ECS name ecs-f5a2 to go to the page providing details about the ECS.
  4. Click the Security Groups tab and then to show details about the security group rules. Click Modify Security Group Rule in the upper right corner of the table for the security group rules.
  5. Add an inbound rule, as shown in Figure 3.
    Figure 3 Security group rules

Changing Password Authentication to Key-Pair Authentication

Create a key pair on the management console, bind the key pair to your ECS to change the ECS login mode.

  1. Log in to the management console.
  2. Under Computing, click Elastic Cloud Server to switch to the ECS console.
  3. Create a key pair by following the instructions provided in Creating a Key Pair, and keep the private key file secure.
  4. Choose Service List > Security & Compliance > Data Encryption Workshop. In the left navigation pane, click Key Pair Service.
  5. Click the ECS List tab, locate the row containing ecs-f5a2, and click Bind in the Operation column. Set parameters according to Figure 5, and click OK.

    To disable password authentication, select Disable the password login mode on the Bind Key Pair page, or edit the sshd_config configuration file.

    Figure 4 Bind Key Pair
  6. Log in to the ECS, and edit the sshd_config file to disable password authentication.

    vim /etc/ssh/sshd_config

    Press i to enter insert mode, and configure the data in last several lines according to the following figure.

    Parameter description:

    • PermitRootLogin: specifies whether to allow the root user to log in to the ECS. Set this parameter to yes.
    • UseDNS: specifies whether DNS resolution is allowed. Set this parameter to no.
    • PasswordAuthentication: specifies whether a login is authenticated using a password. Set this parameter to no.
    NOTE:

    During key pair binding in step 5, you have selected "Disable the password login mode". The PasswordAuthentication value should be no. You only need to verify it.

    Press Esc and enter :wq to save the changes and exit.

  7. Run the following command to restart sshd:

    systemctl restart sshd

  8. Attempt to log in to the ECS using Xshell or an SSH client. If password input is unavailable, as shown in Figure 5, the configuration is successful.
    Figure 5 Logging in to the ECS using Xshell

Editing hosts.allow and hosts.deny

The /etc/hosts.allow and /etc/hosts.deny files control remote access. You can configure these files to allow or deny the access from certain IP addresses or IP address ranges to a process running on the Linux ECS.

For example, if SSH is available only to the administrator, you can only allow access from the IP address ranges used by the administrator.

The ECS may be logged in anywhere. You are advised to allow accesses from all IP addresses in /etc/hosts.allow.

vim /etc/hosts.allow

Add sshd:ALL in the last line.

Identify ECS security risks using certain methods, for example, checking the SSH status, to detect risky IP addresses, and add them to /etc/hosts.deny to deny the access from these IP addresses.

Usamos cookies para aprimorar nosso site e sua experiência. Ao continuar a navegar em nosso site, você aceita nossa política de cookies. Saiba mais

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback