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.
586 Results
  • 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 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: ...
    6 By devdojo Docker Linux Basics Ubuntu
  • 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...
    3 By selcukahmet Linux Basics Ubuntu 16.04
  • 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 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 devdojo Docker Linux Basics Networking Ubuntu
  • 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 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...
    1 By bobbyiliev Docker Linux Basics Linux Commands
  • 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

    What are your favorite BASH shortcuts?

    As a SysAdmin/DevOps, I spend a lot of my day in the terminal. Here are my favorite shortcuts!
    Accepted Answer: The below two are particularly useful if you have a very long command. Delete everything from the cursor to the end of the line: Ctrl + k Delete everything from the cursor to the start of the line: Ctrl + u Delete...
    2 By bobbyiliev Linux Basics Linux Commands
  • 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 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 devdojo 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

    Error “useradd: group '100' does not exist”

    I get the above mentioned error when I try to add a user. By trying sudo useradd -u 1200 -g test -c 'studente' student or sudo useradd anyuser I get useradd: group '100' does not exist useradd: the GROUP= configu...
    Accepted Answer: Hi @fkutev22, It seems like you've removed the necessary group. Having said that without providing the necessary Operating System - Ubuntu, Centos, Fedora etc. Most probably it's groupadd -g 100 users but before you ...
    1 By fkutev22 Linux Commands Linux Basics
  • Question

    How do I revert the group ownership of www-data to default?

    I entered sudo usermod -g www-data ftpuser How do I return it to the default values? Is it owned by root? If so it would be: sudo usermod -g www-data root? How do i check the ownership of www-data?
    Accepted Answer: Groups don't have owners. Your first command, sudo usermod -g www-data ftpuser made ftpuser's default group into www-data. If you ran sudo usermod -g www-data root, you would, in kind, make the root user's group be ww...
    2 By belakey Linux Commands Linux Basics Ubuntu 18.04 Nginx LEMP
  • 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

    What is umask? How to set it permanently for a user?

    Recently I've been seeing this question quite a lot so I decided to shade some light about what a umask is, how to set it permanently for a user and explain what's the differences between the following umask values: 0...
    Accepted Answer: On Linux and Unix operating systems, new files are created with a default set of permissions. According to the official man page the description of umask is: umask() sets the calling process's file mode creation mask ...
    1 By bobbyiliev Linux Commands Linux Basics
  • Question

    How to reboot a Droplet with DigitalOcean API - PHP, Python, BASH examples?

    Recently someone asked me how to reboot a Droplet with the DigitalOcean API so I decided to put to together a few examples on how to do that with different scripts including: PHP script Python script BASH script And l...
    Accepted Answer: According to the official API documentation, you can reboot a droplet with the following curl request: curl -X POST -H "Content-Type: application/json" \ -H "Authorization: Bearer <^>API_TOKEN_HERE<^>" \...
    1 By bobbyiliev API Python Linux Basics PHP
  • Question

    How to Tweak MySQL/MariaDB Configuration for Increased Performance and Stability?

    Hi all, Do you have any suggestions on how to make sure that MySQL/MariaDB is configured properly for optimal performance and stability? Thanks!
    Accepted Answer: Hello, What you could do is use the MySQLTuner script (https://github.com/major/MySQLTuner-perl). The MySQLTuner is a script written in Perl and allows you to quickly test your MySQL configuration and it gives you sug...
    1 By devdojo MySQL MariaDB Linux Basics
  • 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 devdojo MySQL Linux Basics