Grid Guides

Explore How System On Grid Can Work For You

Grid Guide Topics

Initial Server Setup with CentOS 7

Table Of Contents


    ## Table of Contents

    – [Introduction](#introduction
    – [Prerequisites](#prerequisites
    – [Initial Server Setup with CentOS 7](#initial-server-setup-with-centos-7
    – [Log in as a Root User](#log-in-as-a-root-user
    – [Create a New User](#create-a-new-user
    – [Give Root Privileges to the New User](#give-root-privileges-to-the-new-user
    – [Add Public Key Authentication](#add-public-key-authentication
    – [Configure SSH Daemon](#configure-ssh-daemon
    – [Conclusion](#conclusion

    ## Introduction

    In this guide, we are going to explain to you how to do the initial server setup with CentOS 7 and some additional recommended steps that you must take to increase the usability and security of your server.

    ## Prerequisites

    A Running Server

    ## Initial Server Setup with CentOS 7

    ## Log in as a Root User

    If you want to log into your server, you need your server’s IP address and the password to your root account.

    Then, you can log into your server with the following command.

    “`
    local$ sudo root@216.200.116.230
    “`

    You will get the following output.

    ![](http://

    Enter “yes” to confirm your authentication and add the host to known hosts.

    ![](http://

    That’s it. You have successfully logged in as a root user.

    ## About Root

    In Linux terminology, a Root is an administrative user with many privileges. But, you are not supposed to use it regularly. This is because of the very broad privileges of the root account and also the ability of it to make hostile changes (accidentally.

    ## Create a New User

    You need to create a New User Account just to avoid the possibility of making hostile changes to your account.
    In this guide, I am creating a new user called systemongrid, but you must replace it with your username.

    “`
    # adduser systemongrid
    “`
    Then, set a password for your user.

    “`
    # passwd systemongrid
    “`

    Output:

    ![](http://

    Enter a strong password for your user and confirm the password by retyping it.

    ## Give Root Privileges to the New User

    Now, you have a new user with some basic account privileges. To use root privileges, you can not always log out the new user account and log into the root account. So, we give root privileges to the new user. This will allow the new user to use administrative privileges and run commands by adding the word ‘sudo’ before every command.

    Add the new user to the “wheel” group using the below command. Because by default on CentOS 7, users in the “wheel” group can use the sudo command.

    “`
    # gpasswd -a systemongrid wheel
    “`

    You have added the new user to the “wheel” group and can run commands with root privileges using the sudo command.

    ## Add Public Key Authentication

    This step is to increase the usability and security of your server by adding public key authentication for your new user.

    ## Generate a Key Pair

    You need to generate an SSH key pair, which consists of a public key and a private key. (If you already have generated an SSH key pair, you can skip to the next step, Copy the Public Key.

    Generate an SSH key pair using the below command.

    “`
    $ ssh-keygen
    “`

    In this guide, we are using the user, systemongrid. So, the output will look like this.

    Output:

    ![](http://

    Then, you will be asked to enter a passphrase for additional security. You can either enter a strong passphrase or leave it blank.

    ![](http://

    ## Copy the Public Key

    Now, you must place the public key on your server.

    Then, copy the public key into the authorized_keys file in your new machine by using an ssh-copy-id command.

    “`
    $ ssh-copy-id systemongrid@216.200.116.230
    “`

    You will get the following output.

    ![](http://

    This message helps you to make sure that you have not added any extra keys and this is the first time you are connecting to a new host. Type yes, press ENTER to continue. Then, Enter your password to see something like the following.

    ![](http://

    Now, your public key is added to the remote user’s .ssh/authorized_keys file. You can use the corresponding private key to log into your server.

    ## Configure SSH Daemon

    Now you have a new user account, you can increase the security to your server by altering its SSH daemon configuration to disallow remote SSH access to the root account.

    For that, as a root user, open the configuration file in your text editor.

    “`
    # vi /etc/ssh/sshd_config
    “`

    Within the file, find the line that looks like the following.

    “`
    #PermitRootLogin yes
    “`

    Uncomment the line by removing “#” and replace “yes” with “no”. (It should look like the following.

    “`
    PermitRootLogin no
    “`

    Then, save and close the file.

    Now, restart the SSH service to apply the changes that you have made to the configuration file.

    “`
    # systemctl reload sshd
    “`

    Before logging out of the server, let’s confirm if the new connections are established successfully. For this, log into your new user account by opening a new terminal and using SSH with your new user account.

    Then, you are prompted for the new user’s password that you configured. After this, you can log in as a new user.

    And, if you want to run a command with the root privileges, you need to type sudo before it.

    “`
    $ sudo command_to_run
    “`
    If everything is alright, you can exit your sessions by typing

    “`
    $ exit
    “`

    ## Conclusion
    In this guide, you have learned how to do the initial server set up with CentOS 7 and some additional steps that must be taken to increase the usability and security of your server.