Public Key Encryption Using SSH

Let’s look at what SSH means and why it’s one of the necessities towards securing communication between two remote machines. SSH, commonly known as Secure Socket Shell, is a network protocol that allow users a proper and secure communication mechanism with a remote computer over an unsecured network. One of its core functionalities include providing a secure channel- by authenticating and encrypting the channels between two computers that are usually connected over an open network.

In this article we will be looking as to how we can set up SSH in Linux and demonstrate a process of generating keys and implementing Public Key Encryption.

NOTE: ALL OF THIS IS PERFORMED IN CLIENT SIDE. YOU ONLY NEED TO COPY PUBLIC KEY TO THE SERVER USING ssh-copy-id

Let’s get started by installing ssh in our Linux distribution

sudo apt-get install ssh

And now the fun begins. Once installation is complete, we start ssh.

sudo service ssh start

ssh supports various key generation algorithms like RSA, ECDSA, DSA, . For this tutorial we will be using RSA method. In order to generate key we use

ssh-keygen -t rsa //ssh-keygen also generates rsa as its the default method

First, you will need to enter the path as suggested which you would need to save in .ssh directory.

Now, you will be prompted to enter a passphrase. Remember, it as you will need it to login to the server. Two types of keys are generated after a complete execution of the command. One is public key(which will be named as server.pub in this case as we have provided server as file name. Refer to the image above) and as the name suggests, this key is the one you will be handing the computer where you would want to log in. Another is a private key(named as server), which should be kept with you and only you(or your computer in this case). Combination of public key and private key will be used for authenticating your passphrase.

We then have to give the server our public key. We can copy our public key to the server directly using

ssh-copy-id server@server-ip-address

Note: For some reason, there may be an issue using this command. One of the general reasons is that server may not have .ssh directory in its home path. If the command doesn’t execute, you should manually create .ssh directory in by logging in to server.

You should now be able to login to server using passphrase you assigned while generating key.

ssh server@server-ip-address

Step by Step Guide for Setting up LAMP

For a basic complete web server implementation, various components needs to be installed namely – Apache, PHP and MySQL

Step 1: Installing Apache

Installing apache in various Linux distribution is same as installing any other package. You need to use apt-get command.

sudo apt-get install apache2

Step 2: Installing MySQL

Similar to installing Apache, following command will install MySQL

sudo apt-get install mysql-server

Securing MySQL is a priority. In order to do this with a password, use this command

sudo mysql_secure_installation

Executing this command will prompt for a password. This password would be required in order to access any database so be sure to use a strong and secure one.

In order to be able to execute any SQL commands such as creating databases, tables or adding any form of data, you need to be in SQL prompt. Thus, start MySQL server and then login as root providing the password entered during secure installation.

systemctl start mysql

sudo /usr/bin/mysql -u root -p

You should have mysql> as your prompt meaning that you are now able to execute any sql queries. Use exit; to return back to original linux path;

Step 3: Installing PHP

You would need several packages to install fully functional PHP. Install packages depending upon your requirement.

sudo apt-get install php-pear php-fpm php-dev php-zip php-mysql php-xmlrpc php-xml libapache2-mod-php

Once you are done installing, you should restart apache. To confirm if PHP has been installed or not, you can simply use a well known PHP function echo as shown below from linux terminal.

sudo service apache2 restart

php -r ‘echo “PHP should be working if this text is printed.\n”;’

That is all required for proper functioning of a web server. You can check by accessing ‘localhost’ in your machine. Try adding and accessing some PHP files in /var/www/html/ directory to ensure its working properly.

Note: Follow this link to check for any additional packages that may be required for PHP