This article will discuss important tasks to perform in the server for the initial setup with Centos 7 and some basic server security for it.
CentOS, or the Community Enterprise Operating System, is a popular Linux distribution. It’s derived from, and is fully compatible, with Red Hat Enterprise Linux.
CentOS 7 will enjoy support until the end of 2020 and will receive maintenance updates until the end of June 2024.
Initial server setup with centos 7
Root login on centos 7
If you aren’t connecting to your server, log in as the root by the following command:
ssh [email protected]_IP_ADDRESS
Accept the warning about host authenticity, and if it appears, then provide your root authentication. If it is your first time logging into the server, you should change the root password with a password.
Create a new user on centos 7
You can create a new user by the adduser command on centos 7, for example: create a user named orcacore:
Create a password for your user by this command:
Choose a strong password for it.
Root privileges on centos 7
In basic server setup on centos 7 if a normal user wants to use the administrative privileges should put sudo before each command.
To add these privileges to our new user, we need to add the new user to the “wheel” group. By default, on CentOS 7, users who belong to the “wheel” group are allowed to use the sudo command.
You can add your new user to the “wheel” group with the following command:
gpasswd -a orcacore wheel
Add public key authentication for server setup
In the initial server setup with centos 7, you should secure your server by setting up public-key authentication for your new user.
This security requires a private SSH key to log in.
If you already have a public key that you want to use, skip to the Copy the Public Key step. You can generate your new pair (public/private) key by visiting the how to generate SSH key pair article.
After this, you should copy your public key to your new server. You can do this in two ways:
1) Use ssh-copy-id
ssh-copy-id [email protected]_IP_ADDRESS
2) Manually install the key
In your output, you will see your public SSH key, select and copy it.
After this you should add the public key to your new remote user with the following commands:
su – orcacore
Create a new directory and set its permissions on centos 7:
mkdir .ssh chmod 700 .ssh
Then open a file with the vi editor (or your favorite) named authorized_keys:
Enter your public key in your editor save and close the file.
Set permissions for authorized_keys:
chmod 600 .ssh/authorized_keys
Type this command once to return to the root user:
Configure SSH daemon
Now that we have our new account, we can secure our server by modifying its SSH daemon configuration to disallow remote SSH access to the root account.
First, open the configuration file with vi editor as root on centos 7:
in your text editor find the”#PermitRootLogin yes” line and uncomment the line by removing the # from it. Then replace yes with no. save and close the file.
systemctl reload sshd
Now you should test your new configuration.
Open a new terminal window and run this command:
ssh [email protected]_IP_ADDRESS
conclusion of initial server setup with centos 7
At this point, you learn a basic server setup on centos7 and some basic server security for it.
Hope you enjoy this article about the initial server setup with centos 7.