Linux Basics

Linux Basics are essential tools and tips that everyone who works with Linux should know.

Linux Basics subscription active
You will receive email notifications for new publications on Linux Basics.
611 Results
  • Question

    How to fix docker: Got permission denied while trying to connect to the Docker daemon socket

    I've just installed docker but I have to run it with sudo every time. If I don't add sudo I get the following error: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker...
    Accepted Answer: Hello, According to the official Docker docs here: https://docs.docker.com/install/linux/linux-postinstall/#manage-docker-as-a-non-root-user You need to do the following: To create the docker group and add your user: ...
    7 By bitmap Docker Linux Basics Ubuntu
  • Question

    Ubuntu 16.04 - Creating New User and Adding SSH Keys

    I am following the tutorial to add an SSL certificate to the Ubuntu 16.04 (https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-ubuntu-16-04) droplet, but in the instructions it i...
    Accepted Answer: @connordphillips The root user is a super user and the only real super user on the OS by default. You can add sudo users which have permission to escalate to root after authenticating, though root is still a super us...
    5 By connordphillips Linux Basics Linux Commands Nginx Ubuntu 16.04
  • Question

    How to increase SSH Connection timeout?

    Hi everyone! I have an issue about SSH connection. Previously I set /etc/ssh/ssh_config as ConnectionTimeout 0 but still closes connection. So Am I missing something? How can I keep alive connection? What can I do any...
    Accepted Answer: @selcukahmet /etc/ssh_config is the client side configuration file not the server side config file. To prevent all your clients from timing out you need to edit /etc/sshd_config which is the server side configuration...
    4 By selcukahmet Linux Basics Ubuntu 16.04
  • Question

    How to ping Docker container from another container by name?

    Hi all, I want to be able to ping or basically access a running docker container from another container by simply using the docker name rather than an IP address. I've tried a few guides but I could not get it working...
    Accepted Answer: Hello, Yes this now comes more or less out of the box with Docker Networks, so what you need to do is: Create two containers: docker run -d --name <^>web1<^> -p 8001:80 eboraas/apache-php docker run -d --name <^>web...
    1 By bitmap Docker Linux Basics Networking Ubuntu
  • Question

    How to Host Multiple Docker Containers on a Single Droplet with Nginx Reverse Proxy?

    Hi all! Recently I had to setup a few small Docker containers for a couple of small websites. As the sites were really small I didn't want to run each one on a separate Droplet, so instead, I used Nginx with separate...
    Accepted Answer: Prerequisites Before you start, make sure to have Docker and Nginx installed, here's how to do that: To install Docker follow the steps here: https://www.digitalocean.com/community/questions/how-to-install-and-run-doc...
    2 By bobbyiliev Docker Linux Basics Linux Commands
  • Question

    28: No space left on device error

    I was trying to renew my SSL certificate on my droplet by following this guide: https://certbot.eff.org/lets-encrypt/ubuntubionic-nginx But for some reason I kept getting 28: No space left on device when I run apt-get...
    Accepted Answer: Hello, I would recommend starting with the following: First check how much space you have available and which partition is filling up with the following command: df -h The output would look something like this: Fil...
    1 By jenyeji DigitalOcean Let's Encrypt Linux Basics Configuration Management
  • Question

    How to Start Docker Containers Automatically After a Reboot?

    Recently one of my servers crashed and after the reboot, none of my Docker containers started. So I had to manually check each container and start the ones that were required. That is when I realized that I should i...
    Accepted Answer: In order to enable a restart policy, you need to use the --restart argument when executing docker run. In my case what I decided to do is to use the --restart flag with the unless-stopped argument, that way my contai...
    1 By bobbyiliev Docker Linux Basics Linux Commands
  • Question

    How to copy a file from a running Docker container to host?

    As a good practice, you should treat containers as immutable and not make any direct changes during runtime. However, there are some cases when you would need to copy a file from your container to your Docker host for...
    Accepted Answer: In order to copy a file from a running container to your host you first need to get your Docker container ID, you can do that with the following command: command docker ps Then once you have your container ID, you ca...
    1 By bobbyiliev Docker Linux Basics Linux Commands
  • Question

    How to check the disk usage of all running Docker containers?

    With the docker system df command you would get a summary of your Docker usage including things like: The total size of all images The total size of all containers The local volumes size And the cache However, here's ...
    Accepted Answer: By default, if you run docker images you will get the size of each image. However, if you run docker ps you would not get the size of the running containers. To check the size of each running container what you could ...
    1 By bobbyiliev Docker Linux Commands Linux Basics
  • Question

    How to Install Subspace on Ubuntu server?

    Subspace (https://github.com/subspacecommunity/subspace) is a simple opensource WireGuard VPN server graphical user interface(GUI). You can install subspace directly on your server which would allow you to track and c...
    Accepted Answer: Prerequisites In order to complete this guide, you will first need to perform the following tasks on your Ubuntu 18.04 Droplet: Ubuntu 18.04 Droplet Create a sudo user and enable ufw. To set this up, you can follow ou...
    1 By bobbyiliev VPN Linux Basics Ubuntu Networking
  • Question

    How to send emails from a bash script using ssmtp?

    I was recently working on a script to monitor some the TCP connections on one of my DigitalOcean servers and I wanted to receive an email every time the connections count was greater than 200. As I wanted to use SMTP ...
    Accepted Answer: Introduction SSMTP is a tool that delivers emails from a computer or a server to a configured mail host. SSMTP is not an email server itself and does not receive emails or manage a queue. One of its primary uses is ...
    1 By bobbyiliev Linux Basics Linux Commands Email
  • Question

    Nginx not starting: Address already in use (nginx: bind to 0.0.0.0:80 failed)

    Hi all, I just installed Nginx but when I try to start it it fails with the following error: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) If I check the status I get the following output: ``...
    Accepted Answer: Hi there @bitmap, It would usually mean that you have another service running on the same port. And note that you can not have multiple services listening on the same port. The service which is already listening on po...
    1 By bitmap Nginx Linux Basics Linux Commands Ubuntu
  • Question

    How to Automatically Generate Sitemap with Laravel?

    Hi all, I'm almost done with building a small website using Laravel. I'm now working on the SEO side of things and I want to be able to automatically generate the sitemap.xml file on let's say daily basis. Has anyone ...
    Accepted Answer: Hello, I usually use the following package for all of my sites to generate the sitemap.xml file automatically: https://github.com/spatie/laravel-sitemap The setup goes something like this: First install the package vi...
    3 By bitmap PHP Frameworks Linux Basics
  • Question

    Trying to setup a SFTP user with limited access.

    What I want to do I want to add a second user, but restrict what the user can do: Only access a single folder called newsletters, it will be in the public folder. The user needs to be able to upload, delete and rename...
    Accepted Answer: Hi @jtittle Thank you so much for taking the time to read and reply to my post! After following your great instructions, the user user-sftp-only is restricted to just the newsletters folder. user-sftp-only can upload...
    5 By smeehan Security Linux Basics Getting Started Ubuntu 16.04
  • Question

    How to sort out - bash: /bin/rm: Argument list too long

    When running rm * in a directory that contains a lot of individual files might get the following error: command bash: /bin/rm: Argument list too long There are a few ways to delete the files inside that specific dire...
    Accepted Answer: Option 1: Let's say that you don't need the folder, so what you could do is just use rm -r to delete the folder recursively, that way you would basically supply just 1 argument (the folder name), and you will be able ...
    1 By bobbyiliev Linux Basics Linux Commands
  • Question

    How to Troubleshoot Common Nginx Issues on Linux Server?

    I have been seeing this question quite a lot recently, so I decided to put together a few steps on what to do in case your website is not loading. If you are using Apache you could follow these steps here instead: htt...
    Accepted Answer: I would recommend following these steps in case that you are having any problems with your nginx server and you are unsure on what the problem is: Check if nginx is running: systemctl status nginx If nginx is runnin...
    1 By bobbyiliev Nginx Linux Basics Linux Commands
  • Question

    How can I kill all MySQL sleeping queries?

    Hello, I've noticed that I have a lot of sleeping MySQL processes. I tried killing them one by one but there are too many to do so. Does anyone know if there is an easier way to kill all sleeping processes at once? Th...
    Accepted Answer: Hello, Yes, you can kill all of your sleeping connections with this command: for i in `mysql -e "show processlist" | awk '/Sleep/ {print $1}'` ; do mysql -e "KILL $i;"; done However, this is not a permanent solution...
    2 By bitmap MySQL Linux Basics
  • Question

    How to undo the last local commit in Git?

    Recently I was making some changes to a local git repository and I committed some changes and files that I should not have committed. I did not run git push so the changes were only committed to my local Git repositor...
    Accepted Answer: Of course, as with everything, there are multiple solutions. But what I would usually do in this case in order to undo my latest commit and then commit my new changes is the following. Let's say that you made some ch...
    1 By bobbyiliev Git Linux Basics Linux Commands
  • Question

    How to Setup Laravel with DigitalOcean Managed Redis Cluster?

    Redis is an open source, advanced key-value store. It is often referred to as a data structure server since keys can contain strings, hashes, lists, sets, and sorted sets. According to the official Laravel documentati...
    Accepted Answer: Prerequisites: In order to complete this tutorial, you will need: An Ubuntu Droplet with Laravel installed, you can follow the steps from this guide here on How to Install and Configure Laravel with LEMP on Ubuntu 18....
    1 By bobbyiliev Redis PHP PHP Frameworks Ubuntu Linux Basics Linux Commands
  • Question

    How to install Ubuntu with GUI

    Hi - Can someone help me setup a GUI on a fresh Ubuntu 16.04 server? I've taken the following steps: 1) Setup droplet 2) sudo apt-get update 3) sudo apt-get install ubuntu-desktop 4) sudo apt-get install ubuntu-gnome-...
    Accepted Answer: Hi @jtn1490 , You can't just SSH into server and type startx to get Ubuntu with GUI. You should use X11 Forwarding or VNC to get what you want. First solution will not get you a full GUI, but you when you launch any G...
    6 By jtn1490 Linux Basics Ubuntu 16.04