Ubuntu Server Flashcards

1
Q

How do you make a droplet on digital ocean that will host a server?

A

Select the project you want to create the droplet under. Click “create” and “droplet”.

Select the closest region to you. Choose cheapest data center. Choose latest version of Ubuntu. Basic/cheapest options. Use SSH Key, and create that SSH key on your computer.

In a command prompt, type “ssh-keygen” and allow the default file path to go through. Make a password associated with the ssh key. Get the key by typing “cat ~/.ssh/id_rsa.pub”. Copy the output and past it into the appropriate field. Give it a name and enter. This allows you to ssh into the server.

Give it a host name, and create the droplet.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How do you login for the first time and setup your Ubuntu server with Nginx?

A

ssh root@ipAddress

Type password associated with SSH key on your machine

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do you secure your website with Certbot on your Ubuntu server?

A

Install snap if not already installed.

Ensure snap version is up to date:

sudo snap install core
sudo snap refresh core

Make sure certbot hasn’t been installed in some other way:

sudo apt-get remove certbot

Install certbot:

sudo snap install –classic certbot
sudo ln -s /snap/bin/certbot /usr/bin/certbot (ensures certbot command can be run)

Get certificates:

sudo certbot –nginx

Follow prompts!

Test test automatic renewal:

sudo certbot renew –dry-run

Now go to your website to see if it is secure!

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How do you configure an ubuntu server to have nginx, run nodejs and npm, have the vue/cli, accept github pull requests, allow refreshes to non-root pages, and allow secure connections, including ssh? Why should you be careful on this last one?

A

First run:

sudo apt update

This must be done to perform the next commands correctly.

sudo apt install nginx
sudo apt install nodejs
sudo apt install npm

These 3 should be properly installed.

Now for the vue/cli:

npm install -g @vue/cli

To be able to pull your git repository, run:

ssh-keygen

This will make the rsa keys necessary to push/pull from anywhere. Remember the password if you make one as it will be when you do a pull request I believe. Go to the folder it was created in, something like /root/.ssh/. Run:

cat id_rsa.pub

Copy the result. Go to GitHub settings, SSH and GPG keys, New SSH Key, paste the public key into the field, title it, and now you can make pull requests on the server.

When pulling a project, remember to run npm install in the app to make sure

To allow refreshes to non-root pages, go to:

cd /etc/nginx/sites-available/

vi default (or whatever the config you’re using is.)

Change under location / {

}

There is a place where it says =404;
Replace that with /index.html;

Now refreshing the page on your vuejs project wont return a 404 error.

For secure connections, you need to use the ufw command. DO NOT enable this unless you are planning on allowing ssh or else you won’t be able to ssh back into the server.

sudo ufw allow ssh
sudo ufw allow 80
sudo ufw allow 443

80 is for http connections and 443 is for https connections. After these are allowed:

sudo ufw enable

Check the status with

sudo ufw status verbose

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do you include pre-rendering of web pages on your server? (This is necessary for SEO in Vue projects, for example, where there aren’t multiple html web pages but there needs to be for SEO.)

A

npm install –save-dev prerender-spa-plugin

Then include this in your vue project vue.config.js:

// vue.config.js
const PrerenderSPAPlugin = require(‘prerender-spa-plugin’);
const path = require(‘path’);

module.exports = {
configureWebpack: config => {
if (process.env.NODE_ENV !== ‘production’) return;

return {
  plugins: [
    new PrerenderSPAPlugin({
      // Required - The path to the webpack-outputted app to prerender.
      staticDir: path.join(\_\_dirname, 'dist'),
      // Required - Routes to render.
      routes: ['/', '/about', '/contact'],
    })
  ]
};   } };

In the “route” container, include all the routes you want prerendered.

You may have other things within the module.exports such as routing api calls to your back end at port 3000 for example.

Then install these dependencies on your ubuntu server:

sudo apt-get install -y libx11-xcb1 libxcomposite1 libxi6 libxext6 libxtst6 libnss3 libcups2 libxss1 libxrandr2 libasound2 libpangocairo-1.0-0 libatk1.0-0 libatk-bridge2.0-0 libgtk-3-0

These allow connection to Chrome, which is apparently necessary for the prerender-spa-plugin.

If you want to do SSR (server-side rendering), create a nuxt project, which is a framework built on top of Vue.js to streamline development.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How do you configure your sites-available file in nginx to handle a site that is not served statically through /var/www/site for example?

A

You don’t give it a root. Just provide the server name and make the “location /” bracket a proxy_pass to http://localhost:3000 or whatever port the program is running on.

server {
server_name bhsite.hartecho.com www.bhsite.hartecho.com;

    location / {
            proxy_pass http://localhost:3005;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection 'upgrade';
            proxy_set_header Host $host;
            proxy_cache_bypass $http_upgrade;
    }

listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/hartecho.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/hartecho.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}

server {
if ($host = www.bhsite.hartecho.com) {
return 301 https://$host$request_uri;
} # managed by Certbot

if ($host = bhsite.hartecho.com) {
    return 301 https://$host$request_uri;
} # managed by Certbot

   server_name bhsite.hartecho.com www.bhsite.hartecho.com;
listen 3000;
return 404; # managed by Certbot }

server {
if ($host = www.bhsite.hartecho.com) {
return 301 https://$host$request_uri;
} # managed by Certbot

if ($host = bhsite.hartecho.com) {
    return 301 https://$host$request_uri;
} # managed by Certbot
How well did you know this?
1
Not at all
2
3
4
5
Perfectly