Create New User And Add SSH Login In Linux Server

Hello devs,

In this tutorial, I will discuss how to ssh into a server using the terminal. If you are a Linux administrator or a DevOps, you are always to be concerned about the security of your Linux web server. So I am here to help you with how to make your linux server more secure?

If you are a Linux user then you will know that, Linux server has a default root user as we all know. An hacker can easily take a guess about the root user and can try to break into a Linux system.

However, if we disable the root user he might not be able to guess the root user. So let's see how to create a new user and disable root user in linux server.

Create a new admin user in Linux

# ssh with root user
$ ssh root@YOUR_SERVER_IP

# create alternate user called admin
$ useradd -m -d /home/admin admin

# make sure home directory created and has user permissions
$ ls -lad /home/admin

# update new user password
$ passwd admin

# add sudoer permission to new user
$ echo 'admin ALL=(ALL) ALL' >> /etc/sudoers

# now exit the terminal and make sure you
# can ssh with new admin user before you disable root login
$ exit​


Disable ssh login for the root user in Linux

Once we have a new sudo user created from the above command then we will disable ssh login for our root user.

$ ssh root@YOUR_SERVER_IP

# once confirmed log in as root and open following file
$ nano etc/ssh/sshd_config

# find the PermitRootLogin line and change it to
PermitRootLogin no

# save your changes and restart the ssh
$ sudo service sshd restart

# now logout and try to login with root user
# it should not allow ssh for root user
$ exit
$ ssh root@YOUR_SERVER_IP

# if above step works then try login with
# newly created admin user to login via ssh
$ ssh admin@YOUR_SERVER_IP

# exit the server
$ exit​


But keep remembering that you would like to move in root user. So If you want to perform root-level operations for our new admin user then we have to switch to sudo mode and run commands as the root user like below:

# login using admin user
$ ssh admin@YOUR_SERVER_IP

# try to switch with root user
# enter root password
$ su​

//this su means #switch user


Hope it can help you.


#linux #linux-server #ssh