Linux Commands

Linux users can interact with their machines through a wide assortment of different commands. Here, we have in-depth explanations of a variety of these commands.

Linux Commands subscription active
You will receive email notifications for new publications on Linux Commands.
474 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 open PORT : 443

    I have checked that the port 443 is closed and is not listed on my droplet. Here is the output when i run the command : root@ubuntu-1gb-blr1-01:/# netstat -ntlp | grep LISTEN tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN 4...
    Accepted Answer: Let's list the services that are running: sudo lsof -iTCP -sTCP:LISTEN -P Do you see Apache on port 443 on the list? If yes, then it might be a firewall issue. If no, then Apache isn't listening on port 443, which p...
    3 By atulroyal Apache Firewall Linux Commands 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 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

    PhpMyAdmin got 404 not found error on nginx ubuntu 16.04

    Hello Digital Oceans, I'm using ubuntu 16.04 and configured LEMP with this tutorial (https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-in-ubuntu-16-04) on it. I tried to...
    Accepted Answer: @javadroid The symlink created in that guide points to /usr/share/nginx/www while your root directive points to another directory. Unless you specify another location block, NGINX doesn't technically know that the di...
    6 By javadroid Linux Commands Nginx 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

    Can't access droplet, lost key of root, now ssh-copy-id not working Permission denied (publickey)

    I have lost root passphrase of an ssh key now trying to set new key after changing root password from console Also tried to copy in the console but it copy paste don't work !!! ssh-copy-id root@ipaddress /usr/bin/ssh...
    Accepted Answer: Hello, I would recommend following the steps from the official documentation on how to recover from Lost SSH Keys: https://www.digitalocean.com/docs/droplets/resources/lost-ssh-key/ Hope that this helps! Regards, Bobby
    1 By jahangirkobir Linux Commands DigitalOcean Ubuntu 18.04
  • 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

    How to run a command with time limit in Linux

    I recently were asked if there is an option to execute a command but also to specify a time limit (timeout) so the command can be executed for a certain amount of time.
    Accepted Answer: This is possible with the build-in command timeout. Linux has a command-line utility called a timeout, which enables you to execute a command with a time limit. The syntax is as follows. timeout [OPTION] DURATION COM...
    1 By alexdo Linux Commands Ubuntu
  • 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 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 to Check if Running as root in a BASH Script?

    I'm working on a BASH script but I do not want to allow people to run the script as root for security measures. Does anyone know what's the best way to stop the execution of the script if it is ran as root?
    Accepted Answer: Hello, There are a few ways to check that. But how I usually do that is to check if the $EUID matches 0. So the script would look something like this: ```bash !/bin/bash if (( $EUID == 0 )); then echo "Please do n...
    3 By ServerEnthusiast Linux Basics Linux Commands
  • Question

    How to import Geopackages into Postgres/Postgis database?

    Hi everyone, I would like to know how to import a Geopackage file containing raster into a Postgis database. I tried with gdal library "ogr2ogr". This is the command line I used: ogr2ogr -f PostgreSQL PG:"dbname='data...
    Accepted Answer: Hello, I think that your firewall might be blocking your connections on port 5432, so I would suggest running the command locally from your Droplet. What you should usually do is: SSH to your Droplet (https://www.digi...
    1 By Heryx PostgreSQL Linux Commands Linux Basics
  • Question

    How to find the processes that are consuming the most server resources?

    Recently I've been getting this question quite a lot so I decided to share my thoughts with the community!
    Accepted Answer: One of the tools that I use to do so is the top command. Thye top command works quite well, all you need to do is to run top in your terminal and then hit one of the following keys to sort the processes by the informa...
    1 By bobbyiliev Linux Basics Linux Commands
  • Question

    How to Troubleshoot Common Apache 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 that your website is not loading. If you are using Nginx, you could follow the steps here: https://...
    Accepted Answer: I would recommend following these steps in case that you are having any problems with your Apache server and you are unsure about what the problem is: Check if Apache is running: systemctl status apache2 If Apache i...
    2 By bobbyiliev Apache Linux Basics Linux Commands
  • Question

    What is the difference between rm and rm -rf?

    I was recently asked what is the difference between rm and rm -rf and I thought that it would be nice to share the answer with here as well.
    Accepted Answer: If you only run rm it would only delete the named files and not directories. A rundown of the -rf arguments: -r, -R, --recursive - is used to recursively delete the content of a directory, including hidden files and s...
    1 By bobbyiliev Linux Basics Linux Commands