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.
496 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 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

    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 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

    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

    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 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

    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 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

    Update MySQL version cPanel/WHM using API / command line / Terminal

    Recently I was asked if there is a way to update the MySQL version using the command line and which is the best way to do this.
    Accepted Answer: There a few ways to update MySQL or MariaDB and one of them is doing this via the command line / terminal and I would like to share the process with you. Introduction cPanel is one of the most popular Linux-based cont...
    1 By alexdo CentOS MySQL MariaDB 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

    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 solve this error with the yum and dnf commands? [Failed to download metadata for repo 'dovecot-2.3-latest']

    Hi! Whenever I use the YUM or DNF command, I get the message below: ``` yum update ``` DigitalOcean Agent 80 kB/s | 3.3 kB 00:00 Dovecot 2.3...
    Accepted Answer: Hi @mcastro05, It seems like it can't find the latest dovecot repo. You can disable it on your server. To disable the said repo, you can ssh to your droplet ssh root@YourDropletIP Enter your repo's folder, it's /et...
    1 By mcastro05 CentOS CentOS 8 Linux Commands
  • Question

    How to Trim String in bash?

    Hi all, Is there an easy way to trim a string in bash? For example if I wanted to trim a string with JS, I could simply do string.trim();. However as far as I can see there is no such command in bash: command trim Th...
    Accepted Answer: Hello, There are multiple ways to do this depending on what exactly you would like to achieve. One of the most straight forward ways to trim a string in bash is to use the xargs command. Here's a quick example: bash e...
    1 By bitmap Linux Basics Linux Commands
  • Question

    Mini tutorial : Restricting sudo users to only a handful commands

    Hi all, I've been asked this question a lot of times - 'Can we restrict sudo users to only a handfull commands?'. In this mini tutorial, I'll show you how you can do that.
    Accepted Answer: Alright, let's begin, First thing's first, we'll need to have a user created which will add to the 'sudo' group. To do that, ssh to your server as root ssh root@YourDropletIp Once you are in, to create the user we'l...
    1 By KFSys Ubuntu CentOS Linux Basics Linux Commands
  • Question

    Problem with copy-paste into DigitalOcean Droplet´s Console window

    I am trying to import the RSA-key of an SSH key-pair by copy-pasting into the Console, the windowed terminal application that opens when you click "console" on the Droplet page. The prompt only seems to accept normal...
    Accepted Answer: The issue with the console app doesn´t seem to be improving and there is no solution, but this is another one: @cjw199 answer to “copy and paste into console (https://www.digitalocean.com/community/questions/copy-and-...
    2 By lausguy Ubuntu 18.04 Linux Commands Ubuntu Apache
  • 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 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...
    8 By bobbyiliev Apache Linux Basics Linux Commands