Normally, there's an ad running in this spot, but you're using an ad blocker. To help support our blog, which provides free tutorials for everybody, we just ask that you whitelist or follow us on facebook, twitter, or subscribe using the form to the leftabove. Thank you!

    Accessing a Remote Server Over SSH

    Select Your OS:

    Once you've generated an SSH key on your local machine, you're going to want to use it to securely access your remote servers in the cloud (or server room). Make sure to go through the prerequisites if you aren't familiar with SSH key generation.

    System requirements

    • A 32-bit or 64-bit computer with at least 8GB of RAM. 16GB or more is recommended.
    • A virtual machine or remote server running Ubuntu 14.04.


    1. Generating a New SSH Key

    Accessing a Remote Server

    You'll need the server's IP address. You'll also need the credentials of a user on the server in order to sign in to the machine for the first time. So if you were to try to ssh into the machine now, without having uploaded the public key, you'd receive the following output and be prompted to enter the user's password.

    Substitute user with the external server user's username and my.external.server.ip with the external server's IP address.

      ssh user@my.external.server.ip
      user@my.external.server.ip password:

    Creating a User on the Remote Machine

    Now that we're able to access our remote machine using our username and password, we'll want to make use of our SSH key, which will allow us to access the remote machine with just our username.

    1. Run the following commands on the remote machine, which should be running Ubuntu 14.04 LTS.
    2.   sudo adduser user
      [sudo] password for ubuntu:
      Adding user `user' ...
      Adding new group `test' (1002) ...
      Adding new user `test' (1002) with group `user' ...
      Creating home directory `/home/user' ...
      Copying files from `/etc/skel' ...
      Enter new UNIX password:
      Retype new UNIX password:
      passwd: password updated successfully
      Changing the user information for user
      Enter the new value, or press ENTER for the default
       Full Name []: 
       Room Number []:
       Work Phone []:
       Home Phone []:
       Other []:
      Is the information correct? [Y/n] Y
    3. Now you'll want to paste the public key you copied from PuttyGen into the ~/.ssh/authorized_keys file on the remote server or virtual machine.
    4. Now, exit the remote server, by running exit from the terminal, and run the following command, from your local machine, which will append your public key to the remote machine's authorized_keys file. If you're using a VM, run:
          cat ~/.ssh/ | ssh vagrant@my.vm.ip.address "cat >> ~/.ssh/authorized_keys"
          ssh vagrant@my.vm.ip.address
      If you are using your own external server, run:
          cat ~/.ssh/ | ssh user@my.external.server.ip "cat >> ~/.ssh/authorized_keys"
          ssh user@my.external.server.ip
    5. Moving forward, when SSHing into the remote machine, you should not be prompted for a password.

    Changing the VMs Hostname on the Local Host Machine

    Open the /etc/hosts and add the following line:

    my.external.server.ip myserver

    Replace my.external.server.ip with the server's actual IP address. Replace myserver with anything you'd like.

    Now you can ssh with ssh user@myserver.


    Now that you know how to SSH into a remote server, you can repeat these steps on any number of remote servers. You can even SSH from one remote server to another. Feel free to experiment with this by setting up a second virtual machine.

    Did you like this tutorial? Help us pay for server costs by following us on Facebook, Twitter, and subscribing below, where you'll get post notifications, training webinar invites, and free bundles.