SSH Installation:

  1. Installation of the OpenSSH client and server applications is simple. To install the OpenSSH client(local server) applications on your Ubuntu system, use this command at a terminal prompt:
    sudo apt install openssh-client
  2. To install the OpenSSH server (remote server) application, and related support files, use this command at a terminal prompt:
    sudo apt install openssh-server

Connect remote server using password

  1. Open terminal in your local OS
  2. Connect with your remote server using the following command line:
    ssh [email protected]

Alternatively if you are using a shared server, it can be set on different ports like 22/2222
So lets assume your remote server running in port: 2222, in that case the connecting command will be:
ssh -p 2222 [email protected]

  1. The system will ask for password, type the Cpanel password that you already have & hit enter button.
    You should be logged in the remote server & you see the remote server in your terminal
    So you have all the access to the remote server via terminal.

Connect remote using SSH Keys

The following method we’ve described its requires passwords each time we will try to access the remote server via SSH.
SSH keys allow authentication between two hosts without the need of a password. SSH key authentication uses two keys, a private key and a public key.

  1. To generate the keys, from a terminal prompt enter:
    imtiaz@imtiaz:~/.ssh$ ssh-keygen -C "[email protected]"
    This will generate the keys using the RSA Algorithm. During the process you will be prompted for a password. Simply hit Enter when prompted to create the key.
    *You can replace the mail address ‘xxxx’ with your email address. By default the public key is saved in the file ~/.ssh/id_rsa.pub, while ~/.ssh/id_rsa is the private key. The key looks like this:
    ssh-rsa AAAAB3NzaC1yc2EAAAADQDMKJKIQXFiJB1ZyoCXrMG6bSZOEu9xhj9SoyiuSZjjBQ29c0DA3jkxdWG8BStbX2VreNypy6AWiMWgA06/9lpw4s49a+x7vOV7SUA5zI0+j+aCoIaoAwdRY+/rjaWqY1PUrSjXj+w1yjnWWgnR+dNoLmX0q6DYPQ/+8KYEZQ3Bw0kOQQhT6UreNOs70bEVuc6FG+NQ4SZE1PJuzNS5b7ekqX3iu8gKFWBgRANytSQ2HQKlnPvjoeGWuDqrSO1 [email protected]
  2. Now copy the id_rsa.pub file content to the remote host and append it to remote ~/.ssh/authorized_keys
    .ssh directory should already be there on the root directory of your remote server. Check if .ssh directory is already available in remote server with:
    ls -a
    It will show the hidden folders on the root directory of the remote server. If there is a folder with name ‘.ssh’ open the directory with:
    cd .ssh
    If the directory is not there then create that with:
    [email protected] [~]# mkdir ~/.ssh
    & change the permission
    [email protected] [~]# chmod 700 ~/.ssh
    then move into the ssh directory with:
    cd .ssh Check the files in this folder with:
    ls -a
    • There should be files named
    1. authorized_keys
    2. known_hosts If not then create those files using command:
    1. touch authorized_keys
    2. touch known_hosts
      Then copy the id_rsa.pub file from your local & write that in the authorized_keys you can do it with any editor, I prefer nano:
      nano authorized_keys
  3. Permission check: Finally, double check the permissions on the authorized_keys file, only the authenticated user should have read and write permissions. If the permissions are not correct change them by:
    chmod 700 .ssh/authorized_keys
  4. Test the connection: Logout from remote server & try to login without password with:
    ssh -p 2222 [email protected]
    *You should now be able to SSH to the host without being prompted for a password.

Some more experimental operation with SSH:

  1. You can do all the git operation if git is installed on the remote server, you can update live code from git directly with command.
    Check if git is already installed or not
    [email protected] [~/public_html]# git --version
  2. You can copy anything from your remote server to local server using:
    imtiaz@imtiaz:/opt/lampp/htdocs$ rsync -av -e "ssh -p 2222" [email protected]:/home/imtiaz/public_html imtiaz_cloud
    Here:
    [email protected] = Remote server
    /home/imtiaz/public_html = the directory we are copying into our local
    imtiaz_cloud = The directory name as we’re copying into our local directory So after completing the copy we will get all the files from our ‘/home/imtiaz/public_html’ remote directory to our local directory ‘/opt/lampp/htdocs/imtiaz_cloud’
  3. We can copy anything to our remoted server from our local server using command:
    imtiaz@imtiaz:/opt/lampp/htdocs$ rsync -av imtiaz_cloud -e "ssh -p 2222" [email protected]:/home/imtiaz/public_html
    Here:
    /opt/lampp/htdocs$ = local directory where file is located
    imtiaz_cloud = directory name that we want to copy to remote
    /home/imtiaz/public_html = remote directory location where we want to copy our local directory.