How to Set Up Server With CentOS

This will help you to do the initial server setup with CentOS.  you will learn to:

  • Set up a new user with root privileges
  • Configure SSH for making secure connection
  • Access your virtual private server with new user

Root Login

Since root login on regular basis is not recommended, we will be creating an alternative user for accessing server. First of all, open your terminal and login to the system as root user.

ssh [email protected]

You can see the following on your terminal:

The authenticity of host ' (' can't be established.

ECDSA key fingerprint is 79:95:46:1a:ab:37:11:8e:86:54:36:38:bb:3c:fa:c0.

Are you sure you want to continue connecting (yes/no)?

Type Y and enter password.


Changing Your Password

You have to change the default root password that was sent while registering your droplet. You may change the password as you wish.


Note: CentOS is particular about the passwords you provide. It may show a bad password notice after entering your password. Either you can ignore that message or set it up to a more complex password.


Creating a New User

Now, you can create a new user for VPS and can grant all root privileges. Here, in this tutorial I have given the name prinsa for the user. You may wish to choose any name you like.

/usr/sbin/adduser prinsa

Create a password for the new user:

passwd prinsa


Granting Root Privileges

We need to grant all root privileges for the new user. It’s required for the administrative capabilities in the virtual server. While performing any root tasks with the new user, always remember to use the ‘sudo’ option. This is highly recommended for two reasons:

  1. It will prevent the user from making any system errors.
  2. It will store all the commands with ‘sudo’ option in a log file for auditing, in case if needed.

Now, let’s edit the sudo configuration.


Search for the user privilege section and update it with the command to grant all root permissions to the newly created user.

# User privilege specification

root    ALL=(ALL)       ALL

prinsa    ALL=(ALL)       ALL

Here is a list of useful commands for using the text editor;

  • The text editor used for configuration file does not accept arrow keys. So you need to use specific keys for navigation.
  • Use ”j” for moving down
  • Use “k” for going up
  • “h” for left and
  • “l” for right
  • Press “a” to begin editing of text
  • Press “esc” and then ”x” for deleting text
  • Press esc, : , w, q and enter to save and exit

After updating, save the file and exit.


SSH Configuration

SSH stands for Secure Shell and it is used to log into a remote server and execute commands. However, this is optional.

Open the ssh configuration file with this command.

sudo vi /etc/ssh/sshd_config

Search for the following section and make the updates wherever necessary.

Port 3500
Protocol 2
PermitRootLogin no
UseDNS no

Here, I have updated the port to 25000. Even though port 22 is the default port, you can change it to any number between 1025 and 65536. However, you need to remember the port number for future log-ins.

Search for PermitRootLogin and change it from ‘yes’ to ‘no’. This will prevent root login in the future. Now you only need to login with the new user.

You can add the following line to the end of the file.

AllowUsers prinsa

Now the configuration changes are done. You can restart and reload SSH so as to implement the new port and settings.

/etc/init.d/sshd reload

For verifying the new settings, open a new terminal window and login to your virtual server using the new user and password. Make sure you have not logged out of root yet.

You can include the new port number and you will see the system prompt with your chosen name.

ssh -p 3500 [email protected]

[[email protected] ~]$

You have logged in successfully to your virtual private server with the new user and you can opt to exit out of root now.


KB Admin has written 46 articles

One thought on “How to Set Up Server With CentOS

Comments are closed.