Skip to content

Letsencrypt Debian

Linux Systems Guides
  • How To Secure Nginx with Let’s Encrypt on Debian 8 PostedDecember 19, 2016 73.2k views Nginx Security Let’s Encrypt Debian Introduction

    Let’s Encrypt is a new Certificate Authority (CA) that provides an easy way to obtain and install free TLS/SSL certificates, thereby enabling encrypted HTTPS on web servers. It simplifies the process by providing a software client, certbot (previously called letsencrypt), that attempts to automate most (if not all) of the required steps. Currently, the entire process of obtaining and installing a certificate is fully automated only on Apache web servers. However, Let’s Encrypt can be used to easily obtain a free SSL certificate, which can be installed manually, regardless of your choice of web server software.

    In this tutorial, we will show you how to use Let’s Encrypt to obtain a free SSL certificate and use it with Nginx on Debian 8. We will also show you how to automatically renew your SSL certificate. If you’re running a different web server, simply follow your web server’s documentation to learn how to use the certificate with your setup.

    Nginx with Let’s Encrypt TLS/SSL Certificate and Auto-renewal Prerequisites

    Before following this tutorial, you’ll need a few things.

    You should have a Debian 8 server with a non-root user who has sudo privileges. You can learn how to set up such a user account by following our initial server setup for Debian 8 tutorial.

    If you haven’t installed Nginx on your server yet, do so by following this guide.

    You must own or control the registered domain name that you wish to use the certificate with. If you do not already have a registered domain name, you may register one with one of the many domain name registrars out there (e.g. Namecheap, GoDaddy, etc.).

    If you haven’t already, be sure to create an A Record that points your domain to the public IP address of your server (if you are using DigitalOcean’s DNS, you can follow this guide). This is required because of how Let’s Encrypt validates that you own the domain it is issuing a certificate for. For example, if you want to obtain a certificate for example.com, that domain must resolve to your server for the validation process to work. Our setup will use example.com and www.example.com as the domain names, so both DNS records are required.

    Once you have all of the prerequisites out of the way, let’s move on to installing the Let’s Encrypt client software. Step 1: Install Certbot, the Let’s Encrypt Client

    The first step to using Let’s Encrypt to obtain an SSL certificate is to install the certbot Let’s Encrypt client on your server.

    The certbot package was not available when Debian 8 was released. To access the certbot package, we will have to enable the Jessie backports repository on our server. This repository can be used to install more recent versions of software than the ones included in the stable repositories.

    Add the backports repository to your server by typing:

    echo 'deb http://ftp.debian.org/debian jessie-backports main' | sudo tee /etc/apt/sources.list.d/backports.list
    

    After adding the new repository, update the apt package index to download information about the new packages:

    sudo apt-get update
    

    Once the repository is updated, you can install the certbot package by targeting the backports repository:

    Note: When using backports, it is recommended to only install the specific packages you require, rather than using the repository for general updates. Backport packages have fewer compatibility guarantees than the main repositories.

    To help avoid accidentally installing or updating packages using this repository, you must explicitly pass the -t flag with the repository name to install packages from backports.

    sudo apt-get install certbot -t jessie-backports
    

    The certbot client should now be ready to use. Step 2: Obtain an SSL Certificate

    Let’s Encrypt provides a variety of ways to obtain SSL certificates, through various plugins. Unlike the Apache plugin, which is covered in a different tutorial, most of the plugins will only help you with obtaining a certificate which you must manually configure your web server to use. Plugins that only obtain certificates, and don’t install them, are referred to as “authenticators” because they are used to authenticate whether a server should be issued a certificate.

    We’ll show you how to use the Webroot plugin to obtain an SSL certificate. How To Use the Webroot Plugin

    The Webroot plugin works by placing a special file in the /.well-known directory within your document root, which can be opened (through your web server) by the Let’s Encrypt service for validation. Depending on your configuration, you may need to explicitly allow access to the /.well-known directory.

    If you haven’t installed Nginx yet, do so by following this tutorial. Continue below when you are finished.

    To ensure that the directory is accessible to Let’s Encrypt for validation, let’s make a quick change to our Nginx configuration. By default, it’s located at /etc/nginx/sites-available/default. We’ll use nano to edit it:

    sudo nano /etc/nginx/sites-available/default
    

    Inside the server block, add this location block: Add to SSL server block

        location ~ /.well-known {
                allow all;
        }
    

    You will also want to look up what your document root is set to by searching for the root directive, as the path is required to use the Webroot plugin. If you’re using the default configuration file, the root will be /var/www/html.

    Save and exit.

    Check your configuration for syntax errors:

    sudo nginx -t
    

    Output nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful

    If no errors are found, restart Nginx with this command:

    sudo systemctl restart nginx
    

    Now that we know our webroot-path, we can use the Webroot plugin to request an SSL certificate with these commands. Here, we are also specifying our domain names with the -d option. If you want a single cert to work with multiple domain names (e.g. example.com and www.example.com), be sure to include all of them. Also, make sure that you replace the highlighted parts with the appropriate webroot path and domain name(s):

    sudo certbot certonly -a webroot --webroot-path=/var/www/html -d example.com -d www.example.com
    

    After certbot initializes, you will be prompted to enter your email and agree to the Let’s Encrypt terms of service. Afterwards, the challenge will run. If everything was successful, you should see an output message that looks something like this:

    Output: IMPORTANT NOTES:

    • Congratulations! Your certificate and chain have been saved at /etc/letsencrypt/live/example.com/fullchain.pem. Your cert will expire on 2017-09-05. To obtain a new or tweaked version of this certificate in the future, simply run certbot again. To non-interactively renew all of your certificates, run “certbot renew”

    • If you lose your account credentials, you can recover through e-mails sent to sammy@example.com.

    • Your account credentials have been saved in your Certbot configuration directory at /etc/letsencrypt. You should make a secure backup of this folder now. This configuration directory will also contain certificates and private keys obtained by Certbot so making regular backups of this folder is ideal.

    • If you like Certbot, please consider supporting our work by:

      Donating to ISRG / Let’s Encrypt: https://letsencrypt.org/donate Donating to EFF: https://eff.org/donate-le

    You will want to note the path and expiration date of your certificate, which was highlighted in the example output.

    Firewall Note: If you receive an error like Failed to connect to host for DVSNI challenge, your server’s firewall may need to be configured to allow TCP traffic on port 80 and 443.

    Note: If your domain is routing through a DNS service like CloudFlare, you will need to temporarily disable it until you have obtained the certificate. Certificate Files

    After obtaining the cert, you will have the following PEM-encoded files:

    cert.pem: Your domain's certificate
    chain.pem: The Let's Encrypt chain certificate
    fullchain.pem: cert.pem and chain.pem combined
    privkey.pem: Your certificate's private key
    

    It’s important that you are aware of the location of the certificate files that were just created, so you can use them in your web server configuration. The files themselves are placed in a subdirectory in /etc/letsencrypt/archive. However, Let’s Encrypt creates symbolic links to the most recent certificate files in the /etc/letsencrypt/live/your_domain_name directory. Because the links will always point to the most recent certificate files, this is the path that you should use to refer to your certificate files.

    You can check that the files exist by running this command (substituting in your domain name):

    sudo ls -l /etc/letsencrypt/live/your_domain_name
    

    The output should be the four previously mentioned certificate files. In a moment, you will configure your web server to use fullchain.pem as the certificate file, and privkey.pem as the certificate key file. Generate Strong Diffie-Hellman Group

    To further increase security, you should also generate a strong Diffie-Hellman group. To generate a 2048-bit group, use this command:

    sudo openssl dhparam -out /etc/ssl/certs/dhparam.pem 2048
    

    This may take a few minutes but when it’s done you will have a strong DH group at /etc/ssl/certs/dhparam.pem. Step 3: Configure TLS/SSL on Web Server (Nginx)

    Now that you have an SSL certificate, you need to configure your Nginx web server to use it.

    We will make a few adjustments to our configuration:

    We will create a configuration snippet containing our SSL key and certificate file locations.
    We will create a configuration snippet containing strong SSL settings that can be used with any certificates in the future.
    We will adjust the Nginx server blocks to handle SSL requests and use the two snippets above.
    

    This method of configuring Nginx will allow us to keep clean server blocks and put common configuration segments into reusable modules. Create a Configuration Snippet Pointing to the SSL Key and Certificate

    First, let’s create a new Nginx configuration snippet in the /etc/nginx/snippets directory.

    To properly distinguish the purpose of this file, we will name it ssl- followed by our domain name, followed by .conf on the end:

    sudo nano /etc/nginx/snippets/ssl-example.com.conf
    

    Within this file, we just need to set the ssl_certificate directive to our certificate file and the ssl_certificate_key to the associated key. In our case, this will look like this: /etc/nginx/snippets/ssl-example.com.conf

    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;

    When you’ve added those lines, save and close the file. Create a Configuration Snippet with Strong Encryption Settings

    Next, we will create another snippet that will define some SSL settings. This will set Nginx up with a strong SSL cipher suite and enable some advanced features that will help keep our server secure.

    The parameters we will set can be reused in future Nginx configurations, so we will give the file a generic name:

    sudo nano /etc/nginx/snippets/ssl-params.conf
    

    To set up Nginx SSL securely, we will be using the recommendations by Remy van Elst on the Cipherli.st site. This site is designed to provide easy-to-consume encryption settings for popular software. You can read more about his decisions regarding the Nginx choices here.

    Note: The default suggested settings on Cipherli.st offer strong security. Sometimes, this comes at the cost of greater client compatibility. If you need to support older clients, there is an alternative list that can be accessed by clicking the link on the link labeled “Yes, give me a ciphersuite that works with legacy / old software.”

    The compatibility list can be used instead of the default suggestions in the configuration below. The choice of which config you use will depend largely on what you need to support.

    For our purposes, we can copy the provided settings in their entirety. We just need to make a few small modifications.

    First, we will add our preferred DNS resolver for upstream requests. We will use Google’s for this guide. We will also go ahead and set the ssl_dhparam setting to point to the Diffie-Hellman file we generated earlier.

    Finally, you should take take a moment to read up on HTTP Strict Transport Security, or HSTS, and specifically about the “preload” functionality. Preloading HSTS provides increased security, but can have far reaching consequences if accidentally enabled or enabled incorrectly. In this guide, we will not preload the settings, but you can modify that if you are sure you understand the implications: /etc/nginx/snippets/ssl-params.conf

    from https://cipherli.st/

    and https://raymii.org/s/tutorials/Strong_SSL_Security_On_nginx.html

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers on; ssl_ciphers “EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH”; ssl_ecdh_curve secp384r1; ssl_session_cache shared:SSL:10m; ssl_session_tickets off; ssl_stapling on; ssl_stapling_verify on; resolver 8.8.8.8 8.8.4.4 valid=300s; resolver_timeout 5s;

    Disable preloading HSTS for now. You can use the commented out header line that includes

    the “preload” directive if you understand the implications.

    #add_header Strict-Transport-Security “max-age=63072000; includeSubdomains; preload”; add_header Strict-Transport-Security “max-age=63072000; includeSubdomains”; add_header X-Frame-Options DENY; add_header X-Content-Type-Options nosniff;

    ssl_dhparam /etc/ssl/certs/dhparam.pem;

    Save and close the file when you are finished. Adjust the Nginx Configuration to Use SSL

    Now that we have our snippets, we can adjust our Nginx configuration to enable SSL.

    We will assume in this guide that you are using the default server block file in the /etc/nginx/sites-available directory. If you are using a different server block file, substitute its name in the below commands.

    Before we go any further, let’s back up our current server block file:

    sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/default.bak
    

    Now, open the server block file to make adjustments:

    sudo nano /etc/nginx/sites-available/default
    

    Inside, your server block probably begins like this: /etc/nginx/sites-available/default

    server { listen 80 default_server; listen [::]:80 default_server;

    # SSL configuration
    
    # listen 443 ssl default_server;
    # listen [::]:443 ssl default_server;
    
    . . .
    

    We will be modifying this configuration so that unencrypted HTTP requests are automatically redirected to encrypted HTTPS. This offers the best security for our sites. If you want to allow both HTTP and HTTPS traffic, use the alternative configuration that follows.

    We will be splitting the configuration into two separate blocks. After the two first listen directives, we will add a server_name directive, set to your server’s domain name. We will then set up a redirect to the second server block we will be creating. Afterwards, we will close this short block: /etc/nginx/sites-available/default

    server { listen 80 default_server; listen [::]:80 default_server; server_name example.com www.example.com; return 301 https://$server_name$request_uri; }

    # SSL configuration
    
    # listen 443 ssl default_server;
    # listen [::]:443 ssl default_server;
    
    . . .
    

    Next, we need to start a new server block directly below to contain the remaining configuration. We can uncomment the two listen directives that use port 443. Afterwards, we just need to include the two snippet files we set up:

    Note: You may only have one listen directive that includes the default_server modifier for each IP version and port combination. If you have other server blocks enabled for these ports that have default_server set, you must remove the modifier from one of the blocks. /etc/nginx/sites-available/default

    server { listen 80 default_server; listen [::]:80 default_server; server_name example.com www.example.com; return 301 https://$server_name$request_uri; }

    server {

    # SSL configuration
    
    listen 443 ssl default_server;
    listen [::]:443 ssl default_server;
    include snippets/ssl-example.com.conf;
    include snippets/ssl-params.conf;
    
    . . .
    

    Save and close the file when you are finished. (Alternative Configuration) Allow Both HTTP and HTTPS Traffic

    If you want or need to allow both encrypted and unencrypted content, you will have to configure Nginx a bit differently. This is generally not recommended if it can be avoided, but in some situations it may be necessary. Basically, we just compress the two separate server blocks into one block and remove the redirect: /etc/nginx/sites-available/default

    server { listen 80 default_server; listen [::]:80 default_server; listen 443 ssl default_server; listen [::]:443 ssl default_server;

    server_name example.com www.example.com;
    include snippets/ssl-example.com.conf;
    include snippets/ssl-params.conf;
    
    . . .
    

    Save and close the file when you are finished. Step 4: Adjust the Firewall

    If you have a firewall enabled, you’ll need to adjust the settings to allow for SSL traffic. The required procedure depends on the firewall software you are using. If you do not have a firewall configured currently, feel free to skip forward. UFW

    If you are using ufw, you can see the current setting by typing:

    sudo ufw status
    

    It will probably look like this, meaning that only HTTP traffic is allowed to the web server:

    Output Status: active

    To Action From


    SSH ALLOW Anywhere WWW ALLOW Anywhere SSH (v6) ALLOW Anywhere (v6) WWW (v6) ALLOW Anywhere (v6)

    To additionally let in HTTPS traffic, we can allow the “WWW Full” profile and then delete the redundant “WWW” profile allowance:

    sudo ufw allow 'WWW Full'
    sudo ufw delete allow 'WWW'
    

    Your status should look like this now:

    sudo ufw status
    

    Output Status: active

    To Action From


    SSH ALLOW Anywhere WWW Full ALLOW Anywhere SSH (v6) ALLOW Anywhere (v6) WWW Full (v6) ALLOW Anywhere (v6)

    HTTPS requests should now be accepted by your server. IPTables

    If you are using iptables, you can see the current rules by typing:

    sudo iptables -S
    

    If you have any rules enabled, they will be displayed. An example configuration might look like this:

    Output -P INPUT DROP -P FORWARD ACCEPT -P OUTPUT ACCEPT -A INPUT -i lo -j ACCEPT -A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT -A INPUT -p tcp -m tcp --dport 22 -j ACCEPT -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT

    The commands needed to open SSL traffic will depend on your current rules. For a basic rule set like the one above, you can add SSL access by typing:

    sudo iptables -I INPUT -p tcp -m tcp --dport 443 -j ACCEPT
    

    If we look at the firewall rules again, we should see the new rule:

    sudo iptables -S
    

    Output -P INPUT DROP -P FORWARD ACCEPT -P OUTPUT ACCEPT -A INPUT -p tcp -m tcp --dport 443 -j ACCEPT -A INPUT -i lo -j ACCEPT -A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT -A INPUT -p tcp -m tcp --dport 22 -j ACCEPT -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT

    If you are using a program to automatically apply iptables rules at boot, you will want to make sure that you update your configuration with the new rule. Step 5: Enabling the Changes in Nginx

    Now that we’ve made our changes and adjusted our firewall, we can restart Nginx to implement our new changes.

    First, we should check to make sure that there are no syntax errors in our files. We can do this by typing:

    sudo nginx -t
    

    If everything is successful, you will get a result that looks like this:

    Output nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful

    If your output matches the above, your configuration file has no syntax errors. We can safely restart Nginx to implement our changes:

    sudo systemctl restart nginx
    

    The Let’s Encrypt TLS/SSL certificate is now in place and the firewall now allows traffic to port 80 and 443. At this point, you should test that the TLS/SSL certificate works by visiting your domain via HTTPS in a web browser.

    You can use the Qualys SSL Labs Report to see how your server configuration scores:

    In a web browser: https://www.ssllabs.com/ssltest/analyze.html?d=example.com

    This may take a few minutes to complete. The SSL setup in this guide should report at least an A rating. Step 6: Set Up Auto Renewal

    Let’s Encrypt certificates are valid for 90 days, but it’s recommended that you renew the certificates every 60 days to allow a margin of error. At the time of this writing, automatic renewal is still not available as a feature of the client itself, but you can manually renew your certificates by running the Let’s Encrypt client with the renew option.

    To trigger the renewal process for all installed domains, run this command:

    sudo certbot renew
    

    Because we recently installed the certificate, the command will only check for the expiration date and print a message informing that the certificate is not due to renewal yet. The output should look similar to this:

    Output: Saving debug log to /var/log/letsencrypt/example.com.log


    Processing /etc/letsencrypt/renewal/example.com.conf

    Cert not yet due for renewal

    The following certs are not due for renewal yet: /etc/letsencrypt/live/example.com/fullchain.pem (skipped) No renewals were attempted.

    Notice that if you created a bundled certificate with multiple domains, only the base domain name will be shown in the output, but the renewal should be valid for all domains included in this certificate.

    A practical way to ensure your certificates won’t get outdated is to create a cron job that will periodically execute the automatic renewal command for you. Since the renewal first checks for the expiration date and only executes the renewal if the certificate is less than 30 days away from expiration, it is safe to create a cron job that runs every week or even every day, for instance.

    Let’s edit the crontab to create a new job that will run the renewal command every week. To edit the crontab for the root user, run:

    sudo crontab -e
    

    If this is your first time using crontab, you may be asked to select your preferred text editor. If you have no strong preference, nano is an easy choice.

    Add the following lines:

    crontab entry 30 2 * * * /usr/bin/certbot renew --noninteractive --renew-hook “/bin/systemctl reload nginx” >> /var/log/le-renew.log

    Save and exit. This will create a new cron job that will execute the certbot renew command every day at 2:30 am, and reload Nginx if a certificate is renewed. The output produced by the command will be piped to a log file located at /var/log/le-renewal.log.

    Note: For more information on how to create and schedule cron jobs, you can check our How to Use Cron to Automate Tasks in a VPS guide.

    https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-debian-8

    • no matching host key type found

      Linux Systems Guides
      1
      +0
      0 Votes
      1 Posts
      121 Views
      No one has replied
    • Install Ruby on Debian

      Linux Systems Guides
      1
      +0
      0 Votes
      1 Posts
      983 Views
      No one has replied
    • Basic file permissions

      Linux Systems Guides
      1
      0 Votes
      1 Posts
      968 Views
      No one has replied
    • Install locate *nix

      Linux Systems Guides
      1
      0 Votes
      1 Posts
      1k Views
      No one has replied
    • Set script to executable

      Linux Systems Guides
      1
      +0
      0 Votes
      1 Posts
      1k Views
      No one has replied
    • 0 Votes
      2 Posts
      733 Views
      lime-itL

      Again running smartctl after all is said and done:

      smartctl --all /dev/sda

      ddrescue-smartctl-after-rescue.png ddrescue-smartctl-2.png

      Yet an old drive in itself, I run the wheels off of them, and monitor regularly as anyone should.

    • 0 Votes
      3 Posts
      3k Views
      rickR

      New script due to dependency changes:

      #! /bin/sh set -e

      if [ “$1” = “install” ] || [ “$1” = “upgrade” ]; then

      ACTION=$1

      elif [ “$1” = “” ]; then ACTION=install else echo “usage: $(basename $0) action [source]” echo “action is either install (default) or upgrade” echo “source is either tar (default) or git” exit 1 fi

      if [ “$2” = “git” ] || [ “$2” = “tar” ]; then SOURCE=$2 elif [ “$2” = “” ]; then SOURCE=tar else echo “Unknown source $2!” exit 1 fi

      if [ “$BPC_UID” ] && [ $(getent passwd “$BPC_UID” | cut -d ‘:’ -f 1) != “backuppc” ]; then echo “The uid = $BPC_UID is already in use!” exit 1 fi

      #Install dependencies

      apt-get -q update export DEBIAN_FRONTEND=noninteractive apt-get install -q -y apache2 apache2-utils libapache2-mod-perl2 par2 perl smbclient rsync tar gcc zlib1g zlib1g-dev rrdtool git make perl-doc libarchive-zip-perl libfile-listing-perl libxml-rss-perl libcgi-session-perl libacl1-dev wget iputils-ping pwgen

      #Set up backuppc user and directory

      if ! id backuppc >/dev/null 2>&1; then if [ “$BPC_UID” ]; then adduser --system --home /var/lib/backuppc --group --disabled-password --shell /bin/false --uid=“$BPC_UID” backuppc else adduser --system --home /var/lib/backuppc --group --disabled-password --shell /bin/false backuppc fi fi mkdir -p /var/lib/backuppc/.ssh chmod 700 /var/lib/backuppc/.ssh echo -e “BatchMode yes\nStrictHostKeyChecking no” > /var/lib/backuppc/.ssh/config if [ ! -e /var/lib/backuppc/.ssh/id_rsa ]; then ssh-keygen -q -t rsa -b 4096 -N ‘’ -C “BackupPC key” -f /var/lib/backuppc/.ssh/id_rsa fi chmod 600 /var/lib/backuppc/.ssh/id_rsa chmod 644 /var/lib/backuppc/.ssh/id_rsa.pub chown -R backuppc:backuppc /var/lib/backuppc/.ssh

      #Set password or read password file

      if [ “$BPC_PASS” ]; then PASSWORD=“$BPC_PASS” elif [ -e /root/password ]; then PASSWORD=$(cat /root/password) chmod 600 /root/password else PASSWORD=$(pwgen -s -1 32) echo “$PASSWORD” > /root/password chmod 600 /root/password fi echo “backuppc:$PASSWORD” | chpasswd backuppc

      #Get BackupPC release versions

      get_latest_release() { wget -q -O - “https://api.github.com/repos/$1/releases/latest” | grep ‘“tag_name”:’ | sed -E ‘s/.“([^”]+)"./\1/’
      } bpcver=$(get_latest_release “backuppc/backuppc”) bpcxsver=$(get_latest_release “backuppc/backuppc-xs”) rsyncbpcver=$(get_latest_release “backuppc/rsync-bpc”)

      mkdir -p /tmp/bpc cd /tmp/bpc

      if [ $SOURCE = “tar” ]; then

      ##Fetch and install latest stable releases

      wget https://github.com/backuppc/backuppc-xs/releases/download/$bpcxsver/BackupPC-XS-$bpcxsver.tar.gz wget https://github.com/backuppc/rsync-bpc/releases/download/$rsyncbpcver/rsync-bpc-$rsyncbpcver.tar.gz wget https://github.com/backuppc/backuppc/releases/download/$bpcver/BackupPC-$bpcver.tar.gz tar -zxf BackupPC-XS-$bpcxsver.tar.gz tar -zxf rsync-bpc-$rsyncbpcver.tar.gz tar -zxf BackupPC-$bpcver.tar.gz cd BackupPC-XS-$bpcxsver perl Makefile.PL make make test make install cd …/rsync-bpc-$rsyncbpcver ./configure make make install cd …/BackupPC-$bpcver fi

      if [ $SOURCE = “git” ]; then

      #Fetch and install the latest development code instead

      git clone https://github.com/backuppc/backuppc.git git clone https://github.com/backuppc/backuppc-xs.git git clone https://github.com/backuppc/rsync-bpc.git cd backuppc-xs perl Makefile.PL make make test make install cd …/rsync-bpc ./configure make make install cd …/backuppc ./makeDist --nosyntaxCheck --releasedate “date -u "+%d %b %Y"” --version ${bpcver}git tar -zxf dist/BackupPC-${bpcver}git.tar.gz cd BackupPC-${bpcver}git fi

      if [ $ACTION = “install” ]; then ./configure.pl --batch --cgi-dir /var/www/cgi-bin/BackupPC --data-dir /var/lib/backuppc --hostname backuppc --html-dir /var/www/html/BackupPC --html-dir-url /BackupPC --install-dir /usr/local/BackupPC fi

      if [ $ACTION = “upgrade” ]; then ./configure.pl --batch --config-path /etc/BackupPC/config.pl fi

      #Set up web server #Note that changing the apache user and group (/etc/apache2/envvars) could cause other services #provided by apache to fail. There are alternatives if you don’t want to change the apache #user: use SCGI or a setuid BackupPC_Admin script - see the docs. cp httpd/BackupPC.conf /etc/apache2/conf-available/backuppc.conf sed -i “/Require local/d” /etc/apache2/conf-available/backuppc.conf sed -i “s/export APACHE_RUN_USER=www-data/export APACHE_RUN_USER=backuppc/” /etc/apache2/envvars sed -i “s/export APACHE_RUN_GROUP=www-data/export APACHE_RUN_GROUP=backuppc/” /etc/apache2/envvars echo ‘’ > /var/www/html/index.html a2enconf backuppc a2enmod cgid service apache2 restart

      #Set up backuppc service

      cp systemd/init.d/debian-backuppc /etc/init.d/backuppc

      chmod 755 /etc/init.d/backuppc

      update-rc.d backuppc defaults

      chmod u-s /var/www/cgi-bin/BackupPC/BackupPC_Admin

      touch /etc/BackupPC/BackupPC.users

      sed -i “s/$Conf{CgiAdminUserGroup}.*/$Conf{CgiAdminUserGroup} = ‘backuppc’;/” /etc/BackupPC/config.pl

      sed -i “s/$Conf{CgiAdminUsers}.*/$Conf{CgiAdminUsers} = ‘backuppc’;/” /etc/BackupPC/config.pl

      chown -R backuppc:backuppc /etc/BackupPC

      echo $PASSWORD | htpasswd -i /etc/BackupPC/BackupPC.users backuppc

      service backuppc start

      #Clean up

      cd rm -rf /tmp/bpc echo “All done!” exit 0

    • Basic Linux Terminal Commands

      Pinned Linux Systems Guides
      8
      1 Votes
      8 Posts
      7k Views
      rickR

      To list all files in current directory including dot files (hidden files or directories), as well as print permissions :

      ls -la

FreeBSD Notes
  • Unable to negotiate with 10.10.1.35 port 22: no matching host key type found. Their offer: ssh-rsa,ssh-dss

    While attempting ssh this error is generally due to mismatched versions of ssh, where an up to date version is attempting to access an older version

    Add the following to your command :

    The proper way:

    ssh -o KexAlgorithms=diffie-hellman-group14-sha1 -oHostKeyAlgorithms=+ssh-dss 10.10.1.35

    The cheap way:

    Example :

    ssh -oHostKeyAlgorithms=+ssh-dss 10.10.1.35

    or ssh -oHostKeyAlgorithms=+ssh-dss user@10.10.1.35

    This can be added to the ~/.ssh/config file

    Host my-server HostName 10.10.1.35 HostKeyAlgorithms=+ssh-dss
    read more

  • Locate hard drive and get information

    ls -l /sys/block | grep sd.

    Output:

    lrwxrwxrwx 1 root root 0 Jun 22 06:28 sda -> ../devices/pci0000:00/0000:00:1f.2/ata1/host0/target0:0:0/0:0:0:0/block/sda lrwxrwxrwx 1 root root 0 Jun 22 06:28 sdb -> ../devices/pci0000:00/0000:00:1f.2/ata2/host1/target1:0:0/1:0:0:0/block/sdb lrwxrwxrwx 1 root root 0 Jun 22 06:28 sdc -> ../devices/pci0000:00/0000:00:1f.2/ata3/host2/target2:0:0/2:0:0:0/block/sdc lrwxrwxrwx 1 root root 0 Jun 22 06:28 sdd -> ../devices/pci0000:00/0000:00:1f.2/ata4/host3/target3:0:0/3:0:0:0/block/sdd

    Or for a more detailed view

    strace -e trace=open lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS sda 8:0 0 3.6T 0 disk ├─data--2-data--2_tmeta 252:3 0 15.9G 0 lvm │ └─data--2-data--2-tpool 252:9 0 3.6T 0 lvm │ ├─data--2-data--2 252:10 0 3.6T 1 lvm │ ├─data--2-vm--101--disk--0 252:11 0 8G 0 lvm │ ├─data--2-vm--103--disk--0 252:12 0 32G 0 lvm │ ├─data--2-vm--107--disk--0 252:13 0 500G 0 lvm │ └─data--2-vm--108--disk--0 252:20 0 100G 0 lvm └─data--2-data--2_tdata 252:6 0 3.6T 0 lvm └─data--2-data--2-tpool 252:9 0 3.6T 0 lvm ├─data--2-data--2 252:10 0 3.6T 1 lvm ├─data--2-vm--101--disk--0 252:11 0 8G 0 lvm ├─data--2-vm--103--disk--0 252:12 0 32G 0 lvm ├─data--2-vm--107--disk--0 252:13 0 500G 0 lvm └─data--2-vm--108--disk--0 252:20 0 100G 0 lvm sdb 8:16 0 698.6G 0 disk └─sdb1 8:17 0 698.6G 0 part /mnt/pve/backups sdc 8:32 0 3.6T 0 disk ├─vm--data-vm--data_tmeta 252:4 0 15.9G 0 lvm │ └─vm--data-vm--data-tpool 252:14 0 3.6T 0 lvm │ ├─vm--data-vm--data 252:15 0 3.6T 1 lvm │ ├─vm--data-vm--100--disk--0 252:16 0 270G 0 lvm │ ├─vm--data-vm--102--disk--0 252:17 0 100G 0 lvm │ ├─vm--data-vm--104--disk--0 252:18 0 25G 0 lvm │ └─vm--data-vm--106--disk--0 252:19 0 32G 0 lvm └─vm--data-vm--data_tdata 252:7 0 3.6T 0 lvm └─vm--data-vm--data-tpool 252:14 0 3.6T 0 lvm ├─vm--data-vm--data 252:15 0 3.6T 1 lvm ├─vm--data-vm--100--disk--0 252:16 0 270G 0 lvm ├─vm--data-vm--102--disk--0 252:17 0 100G 0 lvm ├─vm--data-vm--104--disk--0 252:18 0 25G 0 lvm └─vm--data-vm--106--disk--0 252:19 0 32G 0 lvm sdd 8:48 0 931.5G 0 disk ├─sdd1 8:49 0 1007K 0 part ├─sdd2 8:50 0 1G 0 part └─sdd3 8:51 0 930.5G 0 part ├─pve-swap 252:0 0 8G 0 lvm [SWAP] ├─pve-root 252:1 0 96G 0 lvm / ├─pve-data_tmeta 252:2 0 8.1G 0 lvm │ └─pve-data 252:8 0 794.3G 0 lvm └─pve-data_tdata 252:5 0 794.3G 0 lvm └─pve-data 252:8 0 794.3G 0 lvm +++ exited with 0 +++ cat /proc/partitions major minor #blocks name 8 0 3907018584 sda 8 16 732574584 sdb 8 17 732572672 sdb1 8 32 3907018584 sdc 8 48 976762584 sdd 8 49 1007 sdd1 8 50 1048576 sdd2 8 51 975712967 sdd3 252 0 8388608 dm-0 252 1 100663296 dm-1 252 2 8495104 dm-2 252 3 16650240 dm-3 252 4 16650240 dm-4 252 6 3873329152 dm-6 252 5 832888832 dm-5 252 7 3873329152 dm-7 252 8 832888832 dm-8 252 9 3873329152 dm-9 252 10 3873329152 dm-10 252 11 8388608 dm-11 252 12 33554432 dm-12 252 13 524288000 dm-13 252 14 3873329152 dm-14 252 15 3873329152 dm-15 252 16 283115520 dm-16 252 17 104857600 dm-17 252 18 26214400 dm-18 252 19 33554432 dm-19 252 20 104857600 dm-20

    Locate drive by serial and model information

    hdparm -i /dev/sda /dev/sda: Model=WDC WD4000FYYZ-05UL1B0, FwRev=00.0NS05, SerialNo=WD-WCC132262513 Config={ HardSect NotMFM HdSw>15uSec SpinMotCtl Fixed DTR>5Mbs FmtGapReq } RawCHS=16383/16/63, TrkSize=0, SectSize=0, ECCbytes=0 BuffType=unknown, BuffSize=unknown, MaxMultSect=16, MultSect=off CurCHS=16383/16/63, CurSects=16514064, LBA=yes, LBAsects=7814037168 IORDY=on/off, tPIO={min:120,w/IORDY:120}, tDMA={min:120,rec:120} PIO modes: pio0 pio3 pio4 DMA modes: mdma0 mdma1 mdma2 UDMA modes: udma0 udma1 udma2 udma3 udma4 udma5 *udma6 AdvancedPM=yes: unknown setting WriteCache=disabled Drive conforms to: Unspecified: ATA/ATAPI-1,2,3,4,5,6,7 * signifies the current active mode
    read more

  • Screen recording can use webm as their format, it can be more simple to use a gif to embed into a website or forum, than adding scripts to host different video format.

    In this case I grabbed a screen record of the progress for writing zeros to a hard drive with dd

    Use ffmpeg to convert webm to gif:

    First create a pallet:

    Move into the directory which the webm is located, or type in the path

    Where ‘dd.webm’ is the screen recording

    ffmpeg -y -i dd.webm -vf palettegen palette.png

    Output:

    dd-ffmpeg.png

    Then convert the webm to gif:

    ffmpeg -y -i dd.webm -i palette.png -filter_complex paletteuse -r 10 dd.gif

    dd-webm-2.png

    This is what I ended up with, looks like any image of any alien on the interwebz, as if shot through a potato, some tweaking of the command is in my future. None the less.

    dd.gif

    read more

  • Write zeros to all sectors

    Use the command ‘lsblk’ to find the drive you wish to erase

    I’m using ‘dd’ to erase things

    In this case I’m torching sdb

    Only use status=progress if you care it’s not necessary

    dd if=/dev/zero of=/dev/sdb bs=12M status=progress

    dd.gif

    read more

  • Remove old kernel images that are cluttering the system

    zstd-no-space-error.png

    Most of these errors are due to low or not enough space left in the root partition.

    If you are using a Debian flavor:

    sudo apt-get autoremove --purge

    zstd-error.png

    Inform grub whenever an old kernel is removed:

    update-grub

    update-grub.png

    Remove the un-used kernel config files:

    These will be the files pre cursed as ‘rc’ where installed kernels use ‘ii’

    … As well as files no longer used or required due to dependencies

    This command will detect, print, and remove left over cruft from previously installed packages or scripts, that have been removed or updated.

    sudo dpkg --purge $(dpkg -l | awk '/^rc/{print $2}')

    purge.png

    You can re-run the following to view the installed kernel(s):

    dpkg --list | grep linux-image

    installed-kernels.png

    read more