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

How to initialize and configure a linux server

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

Usually we can think of the server as a supercomputer with powerful configuration, and it also has its own independent operating system, in which the core system is a server based on Linux system, which we can all call Linux server. When the server is leased, we can usually choose the operating system of the server according to our preferences and operating habits.

Modify root password

The root account does not have a password by default. For security reasons, initialize one first.

Passwd

Create a Linux administrator account

When using Linux server, try not to use root account, deal with daily operations, we create a new administrator account.

First, add a user group (here my custom admin).

Addgroup admin

Then, add a new user (assuming www).

Useradd-d / home/www-s / bin/bash-m www

In the above command, parameter d specifies the user's home directory, parameter s specifies the user's shell, and parameter m means that if the directory does not exist, the directory is created.

Next, set the password for the new user.

Passwd www

Add a new user (www) to the user group (admin).

Usermod-a-G admin www

Next, set sudo permissions for the new user.

Sudo vi / etc/sudoers

Find the following line.

Root ALL= (ALL:ALL) ALL

At the bottom of this line, add another line.

Root ALL= (ALL:ALL) ALLwww ALL= (ALL) NOPASSWD: ALL

The NOPASSWD above indicates that when switching sudo, you do not need to enter a password. For security reasons, you can also force a password.

Root ALL= (ALL:ALL) ALLwww ALL= (ALL:ALL) ALL

Finally, log out of the root user, and then log in as the new user.

Configure the SSH service

Save the ssh public key of your computer to the server's ~ / .ssh/authorized_keys file

Use the following command directly

Ssh-copy-id-I / .ssh/id_rsa.pub root@123.456.78

Then, go to the server and edit the SSH configuration file / etc/ssh/sshd_config.

Sudo cp / etc/ssh/sshd_config ~ (backup, restore) sudo vi / etc/ssh/sshd_config

In the configuration file, change the default port 22 of SSH. Suppose you use 25000

Port 25000

Then, check that several settings are set to the following, and make sure the previous # sign is removed.

The above is mainly to prohibit root users from logging in, as well as to prohibit login with passwords.

After saving, exit the file editing.

Next, change the permissions of the authorized_keys file.

Sudo chmod 600 ~ / .ssh/authorized_keys & & chmod 700 ~ / .ssh/

Restart SSHD

Sudo service ssh restart

Or

Sudo / etc/init.d/ssh restart

Running environment configuration

Check the locale of the server.

Locale

If the result is not en_US.UTF-8, it is recommended to set it.

Sudo locale-gen en_US en_US.UTF-8 en_CA.UTF-8sudo dpkg-reconfigure locales

Then, update the software

Sudo apt-get updatesudo apt-get upgrade

Finally, make some security settings as needed, such as building a firewall and closing ports other than HTTP, HTTPs and SSH.

These are the details of the linux server initialization configuration process, please pay attention to other related articles!

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

Servers

Wechat

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

12
Report