Skip to content

Instantly share code, notes, and snippets.

@kerimdzhanov
Last active December 3, 2017 19:21
Show Gist options
  • Save kerimdzhanov/527b5d0103996efb9218e45de95c773a to your computer and use it in GitHub Desktop.
Save kerimdzhanov/527b5d0103996efb9218e45de95c773a to your computer and use it in GitHub Desktop.
VPS Deployment Instructions

Prerequisites

  • A working Debian/Ubuntu Linux instance

Preparing the deployment server

After creating a VPS drop/node, login as root and update a newly installed system:

$ ssh root@12.34.56.78
# Pasword: ...
# > Welcome to Ubuntu 16.04.3 LTS (GNU/Linux 4.4.0-101-generic x86_64).
# > ...
$ apt-get update
$ apt-get upgrade
$ apt-get dist-upgrade
$ reboot

Wait a minute while system is rebooting, then login again.

Creating a deployer user

First of all, you’d like to add the admin group if it not exists:

$ addgroup admin

You can check admin group privileges using visudo:

$ visudo

There should be something like:

# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL

Now you can create the deployer user:

$ adduser deployer

And add him to the admin group:

$ adduser deployer admin

The deployer user is successfully created, you can logout root:

$ exit

Connecting through the SSH without a password

The next step is optional, but it really helps you to save quite some time. I’m talking about SSH auto-logins, these will prevent the server from asking you for a password every time you’d like to connect.

On your local machine cd into the ~/.ssh directory and generate an RSA key-pair:

$ cd ~/.ssh
$ ssh-keygen -t rsa -C "yourname@yourcompany.com"
# Generating public/private rsa key pair...

To keep things secure, you may want to have a separate key-pair for each server, to make it possible you need to have an ssh configuration file. If you haven‘t created it before, you can do it right now:

$ touch config

Add a new host/rsa entry to your config file:

$ vi config
$ cat config
# ...
# Host yourhost
#  HostName 12.34.56.78
#  IdentityFile ~/.ssh/yourfile_rsa
# ...

Now let’s see the contents of the public key, it should looks like the following:

$ cat yourfile_rsa.pub
# ssh-rsa AAAAb4kzaC1 (text omitted) 86n3iEEQ78cPVazr yourname@yourcompany.com

Now what you have to do is to copy the contents of the created file to your clipboard, we’ll have to write it to a file on our remote server. Start by logging on to the server as deployer, proceed to the user’s .ssh directory and paste your public key into a file called authorized_keys (create it if it doesn’t exist). Save the file and close it, check that the contents have been written to the file and finally disconnect from the server:

$ ssh deployer@yourhost.com
# Password: ...
$ cd ~/.ssh
$ vi authorized_keys
$ cat authorized_keys
# ssh-rsa AAAAb4kzaC1 (text omitted) 86n3iEEQ78cPVazr yourname@yourcompany.com
$ exit

If you’ve done everything right, you should now be able to log on to the remote server from your computer without having to input a password:

$ ssh deployer@yourhost
# > Welcome to Ubuntu 16.04.3 LTS (GNU/Linux 4.4.0-101-generic x86_64).
# > ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment