Before we get started, let’s add another user to the server. It is always a good practice to avoid using root to access the server via ssh.
Create a new user
Use the following command to add a new user:
Enter the password and other info to complete the process.
Now, we need to add the newly created user to the group ‘sudo’
The command to accomplish this is:
usermod -aG sudo <username>
After the user is created successfully, we now need to configure some SSH informations. This will let the user access the server via SSH.
To switch the current user from ‘root’ to a new user, su ( switch user ) command is used.
Lets go to home directory and create a new folder, .ssh:
After these commands, we need to make sure that the folder has correct permissions set up. Run the following command that changes the files permission.
chmod 700 .ssh
After this, we need to dump public keys into authorized_keys section in order to be able to SSH in into the server.
chmod 600 .ssh/authorized_keys
Finally, lets generate a key using the following command:
ssh-keygen -t rsa
In order to view the content of newly generated public key, we can use cat command.
Last but not the least, copy over the text spitted out by the cat command into the authorized_keys. And with that, we can now SSH into the server using the new user credentials.
Now, lets install apache server and host a webpage. First we need to check for upgrades and then install apache.
sudo apt update
sudo apt install apache2
We can check the status of the server using the following command:
systemctl status apache2
sudo apt-get install mysql-server
sudo apt-get install php libapache2-mod-php php-mcrypt php-mysql
These commands will install mySQL and PHP onto the server.
If you want to change the priority according to which the files are served, we need to edit a configuration file located at:
Lastly, we need to restart the server for the changes made to be reflected.
sudo systemctl restart apache2