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
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.
You can see the following on your terminal:
The authenticity of host '188.8.131.52 (184.108.40.206)' 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.
Create a password for the new user:
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:
- It will prevent the user from making any system errors.
- 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 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.
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.
Now the configuration changes are done. You can restart and reload SSH so as to implement the new port and settings.
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.
One thought on “How to Set Up Server With CentOS”
Comments are closed.