One place for hosting & domains

      Beginner’s Guide to the WordPress .htaccess File


      Keeping your site safe should be a top priority for every administrator. WordPress is a secure platform out of the box, but that doesn’t mean it’s impervious to attacks. Fortunately, even if you aren’t a security expert, you can use a file called .htaccess to harden your site’s security policies.

      .htaccess is a configuration file for the Apache web server, which serves many WordPress sites. It’s a powerful tool that helps safeguard your site and boost its performance through some minor tweaks to its code. By editing this file, you can ban users, create redirects, prevent attacks, and even deny access to specific parts of your site.

      An Introduction to the .htaccess File

      .htaccess is short for “HyperText Access.” It’s a configuration file that determines how Apache-based servers interact with your site. In simpler terms, .htaccess controls how files in a directory can be accessed. You can think of it as a guard for your site because it decides who to let in and what they’re allowed to do.

      By default, an .htaccess file is typically included in your WordPress installation. The main purpose of this file is to improve security and performance. Plus, it also enables you to override your web server’s settings.

      You’ll most likely find your .htaccess file in your site’s root directory. Since .htaccess applies to both its own directory and any subdirectories within that main folder, it impacts your entire WordPress site.

      It’s also worth noting that the .htaccess file does not have a file extension. The period at the start simply makes sure the file remains hidden.

      How to Edit Your WordPress .htaccess File

      Editing the .htaccess file is, in practice, as simple as editing any other text file. However, because this is a core file, making changes to it can have unintended consequences.

      For this reason, it’s vitally important that you back up your site before you begin, regardless of whether you’re a beginner or an experienced developer.

      When you’re ready to edit your .htaccess file, you can access it using Secure File Transfer Protocol (SFTP) or Secure Shell (SSH). You will find .htaccess in your site’s root directory:

      WordPress .htaccess file

      Open the file using your preferred text editor, such as TextEdit or Notepad. If the file hasn’t been edited before, you’ll see the following default information:

      WordPress .htaccess file

      It’s important not to add or change anything between the # BEGIN and # END tags. Instead, all new code should be added after this block.

      At this point, all you need to do is add your code and save the file. When you’re including multiple new functions, it’s best to save and test each one separately. If an error occurs, this will make it much easier to troubleshoot which change caused the problem.

      While almost all WordPress installations will already contain an .htaccess file, in some cases, you may need to create one. You can do this using a text editor of your choice, as long as you save it with the right file name: .htaccess with no extension.

      It’s also important to configure the file’s permission settings correctly. You can then upload .htaccess to your site’s root directory.

      9 Things You Can Do With Your WordPress .htaccess File

      Now that you’re familiar with the .htaccess file, it’s time to get up close and personal. We’re going to introduce a number of ways you can easily boost your site’s security and performance by editing this file.

      Simply use the code snippets we’ve provided below, and remember to create a backup before you start!

      1. Deny Access to Parts of Your Site

      One of the most useful things you can do with .htaccess is deny access to certain pages and files. There are a few files you should consider hiding in this way for security reasons, such as your wp-config.php file.

      You can do this by adding the following code, which will cause a 404 error to appear if anybody attempts to view the file:

      <Files ~ "/wp-config.php">
      Order Allow,Deny
      Deny from All
      </Files>

      In cases where sensitive data should be hidden, it can be useful to restrict access to the corresponding directory. Since many WordPress sites use the same folder structure, this setup can leave your site vulnerable. If you add the following line, it will disable the default directory listing functionality:

      Options -Indexes

      This will stop users and robots from viewing your folder structure. If anybody tries to access it, they’ll be shown a 403 error page instead.

      2. Redirect and Rewrite URLs

      Creating redirects enables you to automatically send users to a specific page. Redirects can be particularly useful if a page has moved or been deleted, and you want users who attempt to access that page to be taken somewhere else.

      You can accomplish this with a plugin such as Redirection, but it’s also possible to do it by editing the .htaccess file. To create a redirect, use the following code:

      Redirect /oldfile.html http://www.example.com/newfile.html

      You can probably see what’s going on here. The first part is the path to the old file, while the second part is the URL you want visitors to be redirected to.

      Get Content Delivered Straight to Your Inbox

      Subscribe to our blog and receive great content just like this delivered straight to your inbox.

      3. Force Your Site to Load Securely With HTTPS

      <style>.embed-container { position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden; max-width: 100%; } .embed-container iframe, .embed-container object, .embed-container embed { position: absolute; top: 0; left: 0; width: 100%; height: 100%; }</style><div class=’embed-container’><iframe src=’https://www.youtube.com/embed/QeicRf_Ri3Y’ frameborder=’0′ allowfullscreen></iframe></div>

      If you have added an SSL certificate to your domain, such as DreamHost’s free Let’s Encrypt certificate, it’s a good idea to force your site to load using HTTPS. This will ensure that your site is safer for both you and your visitors.

      You can make it happen by adding the following code:

      RewriteEngine On
      RewriteCond %{HTTPS} !=on
      RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

      Your site will now automatically redirect any HTTP requests and direct them to use HTTPS instead. For example, if a user tries to access http://www.example.com, they will be automatically redirected to https://www.example.com.

      4. Change Caching Settings

      Browser caching is a process where certain website files are temporarily saved on a visitor’s local device to enable pages to load faster. Using .htaccess, you can change the amount of time that your files are stored in the browser cache until they are updated with new versions.

      There are a few different ways to do this, but for this example, we’ll use a function called mod_headers. The following code will change the maximum caching time for all jpg, jpeg, png, and gif files:

      <ifModule mod_headers.c>
      <filesMatch "\\.(jpg|jpeg|png|gif)$">
      Header set Cache-Control "max-age=2592000, public"
      </filesMatch>

      We’ve set the maximum time to 2,592,000 seconds, which equates to 30 days. You can change this amount if you want, as well as the file extensions that will be affected. If you want to add different settings for different extensions, simply add more mod_header functions.

      5. Prevent Certain Script Injection Attacks

      Script injection (or ‘code injection’) attacks attempt to change how a site or application executes by adding invalid code. For example, someone might add a script to a text field on your site and then submit it, which could cause your site to actually run the script.

      You can add the following code to protect against certain types of script injection:

      Options +FollowSymLinks
      RewriteEngine On
      RewriteCond %{QUERY_STRING} (\<|%3C).*script.*(\>|%3E) [NC,OR]
      RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
      RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
      RewriteRule ^(.*)$ index.php [F,L]

      Your site should now be able to detect and stop script injection attempts and redirect the culprit to your index.php page.

      However, it’s important to note that this example will not protect against all types of injection attacks. While this particular code can certainly be useful, you should not use it as your only protection against this type of attack.

      6. Stop Username Enumeration Attacks

      Username enumeration is a process where usernames from your site are harvested by looking at each user’s author page. This is particularly problematic if someone manages to find your admin username, which makes it much easier for bots to gain access to your site.

      You can help prevent username enumeration by adding the following code:

      RewriteCond %{REQUEST_URI} !^/wp-admin [NC]
      RewriteCond %{QUERY_STRING} author=\d
      RewriteRule .* - [R=403,L]

      This will stop certain attempts to enumerate usernames and throw up a 403 error page instead. Bear in mind that this will not prevent all enumeration, and you should test your security thoroughly. We also recommend strengthening your login page further by implementing Multifactor Authentication.

      7. Prevent Image Hotlinking

      Image hotlinking is a common problem that happens when images on your server are being displayed on another site. You can stop this by adding the following code to .htaccess:

      RewriteEngine On
      RewriteCond %{HTTP_REFERER} !^$
      RewriteCond %{HTTP_REFERER} !^https://(www\.)?example.com/.*$ [NC]
      RewriteRule \.(png|gif|jpg|jpeg)$ https://www.example.com/wp-content/uploads/hotlink.gif [R,L]

      Replace example.com with your own domain, and this code will prevent images from loading on all other sites. Instead, the picture you specify on the last line will load. You can use this to send an alternative image to sites that try to display graphics from your server.

      Beware that this may cause issues when you might want images to appear externally, such as on search engines. You might also consider linking to a script instead of a static image, then respond with a watermarked image or an image containing an ad.

      8. Control Your File Extensions

      By using .htaccess, you can control how files of different extensions are loaded by your site. There’s a lot you can do with this feature, such as running files as PHP, but we’re just going to look at a basic example for now.

      The following code will remove the file extension from PHP files when they’re loaded. You can use this with any file type, as long as you replace all instances of “php” with the extension you want:

      RewriteEngine On
      RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\ HTTP/
      RewriteRule ^(.*)index$ http://example.com/$1 [L,R=301]
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule ^([^/]+)/$ http://example.com/$1 [L,R=301]
      RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.+)\.php\ HTTP/
      RewriteRule ^(.+)\.php$ http://example.com/$1 [L,R=301]
      RewriteRule ^([a-z]+)$ /$1.php [L]

      This will cause all PHP files to load without displaying their extension in the URL. For example, the index.php file will appear as just index.

      9. Force Files to Download

      Finally, when a file is requested on your site, the default behavior is to display it in the browser. For example, if you’re hosting an audio file, it will start to play in the browser rather than being saved to the visitor’s computer.

      You can change this by forcing the site to download the file instead. This can be done with the following code:

      AddType application/octet-stream mp3

      In this example, we’ve used mp3 files, but you can use the same function for txt, mov, or any other relevant extension.

      Improve Your Site’s Security and Performance

      The .htaccess file provides flexibility for controlling how your web server behaves. You can also use it to increase your site’s performance and get more control over exactly who can access what information.

      With .htaccess, you can deny access to particular parts of your website. Additionally, it allows you to redirect URLs, force your site to load over HTTPS, and prevent some script injection attacks.

      Editing your .htaccess file is just one way to improve your site’s security. Choosing a secure WordPress hosting provider is another. Check out our DreamPress managed hosting plans to see how we can boost your website’s security and performance!

      Do More with DreamPress

      DreamPress Plus and Pro users get access to Jetpack Professional (and 200+ premium themes) at no added cost!

      Managed WordPress Hosting - DreamPress



      Source link

      Everything You Need to Know About the WordPress functions.php File


      To get involved in WordPress development, you’ll first need to understand how the platform’s most important files work. WordPress makes it pretty easy to tinker with your site. However, it can be difficult to know where to start — or predict what your changes will actually do.

      A perfect place to learn is the functions.php file, which is also known as the functions file. This is a common location for making changes and adding code to WordPress. By editing this file, you can accomplish several useful things, such as adding Google Analytics to your site, creating custom menus, or displaying a post’s estimated reading time.

      What Is the functions.php File?

      The WordPress functions.php file comes with all free and premium WordPress themes. To the untrained eye, it may not look like much, but the functions file is a powerful tool that enables you to do a lot of interesting things:

      WordPress functions.php

      The WordPress Codex describes the functions file like this:

      “You can use it to call functions, both PHP and built-in WordPress, and to define your own functions. You can produce the same results by adding code to a WordPress Plugin or through the WordPress Theme functions file.”

      In simple terms, the functions file enables you to add custom code to your site. It lets you create new functions or reference existing ones in customized ways. As the Codex points out, this makes the functions file very similar to a plugin, but there are some differences between the two.

      The most important difference is that the functions file belongs to a specific theme. If you were to change themes or update to a newer version, the changes you’ve made would disappear.

      For this reason, you should consider creating a child theme and adding the new code to the child’s functions file instead. This way, you can update the parent theme without losing your changes.

      Whether you choose to use the functions file or create a plugin is entirely up to you. For now, let’s look at the different ways you can edit your functions file!

      How to Edit the Functions File (2 Methods)

      Editing your functions file is easy when using a standard text editor, like TextEdit or Notepad. However, before you get started, it is vitally important that you create a backup of your site and save the original, unedited functions.php file. This will enable you to restore your website if something goes wrong during the editing process.

      1. Use the WordPress Editor

      If you have access to the WordPress admin interface, you can edit the functions file directly from the Theme Editor. Go to Appearance > Editor:

      WordPress Theme File Editor

      On the right-hand side of the screen, you will see a list of all your theme files. These differ depending on which theme you use, but one of the options should be Theme Functions (functions.php).

      Simply click on the file to open it in the editor:

      WordPress Theme Editor functions.php file

      Now, you can edit the file directly. Don’t forget to click on Update File at the bottom to save your changes when you’re done.

      2. Access the File Through FTP

      If you are unable to use the admin dashboard or prefer to configure files directly, you can also access the functions file using a Secure File Transfer Protocol (SFTP) client such as FileZilla.

      Open your FTP tool and enter your hosting credentials to connect to your site. To find the right file, navigate to wp-content/themes/[the name of your theme]. When you open this folder, you’ll see the functions.php file:

      editing the WordPress functions.php file through an FTP client

      All you have to do now is to edit it using your preferred text editing software. When you’re done, save the file and overwrite it with the exact same name and extension.

      8 Tricks You Can Accomplish With the WordPress Functions File

      You should now be ready to start editing your functions file. To get you started, we’ll look at some changes that you can make. All you need to do is copy the provided code snippets and paste them on a new line at the very bottom of your functions file (don’t forget to save it!).

      1. Add Google Analytics to Your Site

      There are several ways of integrating Google Analytics with your WordPress site. One of them is by adding your credentials directly to the functions file. This method will insert the tracking code into your site’s header, ensuring that every visit is properly recorded.

      Start by pasting the following code at the bottom of your functions file:

      <?php
      
      add_action('wp_head', 'wpb_add_googleanalytics');
      
      function wpb_add_googleanalytics() { ?>
      
      // Replace this line with your Google Analytics Tracking ID
      
      <?php } ?>

      All you have to do now is to find your Tracking ID and paste it into the line that contains the placeholder text. When you save the functions file, your site will be connected to your Google Analytics account.

      Get Content Delivered Straight to Your Inbox

      Subscribe to our blog and receive great content just like this delivered straight to your inbox.

      2. Change the Default Login Error Message

      By default, when somebody makes an unsuccessful login attempt to a WordPress site, they’ll see an error message like this:

      WordPress default login error message

      Unfortunately, this message is giving potential intruders information about why the attempt didn’t work. A more secure solution is to change this to a generic message instead.

      You can do this easily by adding the following code to your functions file:

      function no_wordpress_errors(){
      return 'Something went wrong!';
      }
      add_filter( 'login_errors', 'no_wordpress_errors' );

      See that Something went wrong! message on the second line? That message will now appear the next time an incorrect login attempt occurs:

      WordPress custom login error message

      You can change the text to whatever you want, as long as you keep the single quote characters. Try it out with different messages to see how it works.

      3. Add the Estimated Reading Time for a Post

      This neat trick enables you to calculate and display the estimated amount of time required to read a post. Your visitors can then get a general idea of the content’s length right away.

      To implement this code, you will need to make two separate edits. The first one happens within the functions.php file, where you’ll want to paste the following snippet:

      function reading_time() {
      $content = get_post_field( 'post_content', $post->ID );
      $word_count = str_word_count( strip_tags( $content ) );
      $readingtime = ceil($word_count / 200);
      if ($readingtime == 1) {
      $timer = " minute";
      } else {
      $timer = " minutes";
      }
      $totalreadingtime = $readingtime . $timer;
      return $totalreadingtime;
      }

      However, this snippet only performs the calculation. You’ll now need to add the following code wherever you want the results to be displayed:

      echo reading_time();

      For example, you could add it to the metadata that appears alongside each post. Every theme is constructed differently, but typically you’ll find it in template-parts > post > content.php:

      WordPress functions.php estimated reading time

      The estimated reading time will now appear in each post’s header alongside the date.

      4. Remove the WordPress Version Number

      Old versions of WordPress may contain security flaws that malicious hackers and bots can exploit. One way to avoid this risk is to hide which version of WordPress your site uses. This is called security through obscurity.

      Before we move on, it’s important to note that obscurity should never be your only security measure. It’s more like adding an extra bulwark to your already secure WordPress fortress.

      Hiding your version number only requires adding the following code snippet to the functions file:

      remove_action('wp_head', 'wp_generator');

      The version number will now be removed from all areas of your site, including its code and your RSS feed.

      5. Automatically Update Your Copyright Notice

      Updating the year in your copyright notice is one of those little tasks that’s easy to forget. Fortunately, you can edit your functions file to automatically generate the copyright date based on the year when your first post was written.

      Paste the following code into your functions file:

      function wpb_copyright() {
      global $wpdb;
      $copyright_dates = $wpdb->get_results("
      SELECT
      YEAR(min(post_date_gmt)) AS firstdate,
      YEAR(max(post_date_gmt)) AS lastdate
      FROM
      $wpdb->posts
      WHERE
      post_status="publish"
      ");
      $output="";
      if($copyright_dates) {
      $copyright = "© " . $copyright_dates[0]->firstdate;
      if($copyright_dates[0]->firstdate != $copyright_dates[0]->lastdate) {
      $copyright .= '-' . $copyright_dates[0]->lastdate;
      }
      $output = $copyright;
      }
      return $output;
      }

      Then add the following code wherever you want the copyright information to be displayed:

      <?php echo wpb_copyright(); ?>

      You’ll now see the dynamically updating copyright date on your site.

      A dynamically-updating copyright date on a website

      In our case, we added the date to the footer.php file, so it would be displayed at the bottom of the page.

      6. Add Custom Menus

      Most themes have pre-defined navigation menus. However, what if you want to create your own menu and place it wherever you want on your site?

      All you need to do is paste this code into your functions file:

      function wpb_custom_new_menu() {
      register_nav_menu('my-custom-menu',__( 'My Customized Menu' ));
      }
      add_action( 'init', 'wpb_custom_new_menu' );

      You can replace ‘My Customized Menu’ with the name you want to give the menu. If you go to Appearance > Menus in your admin area, you should see the new option listed on the page:

      customize your WordPress menus using the functions.php file

      You can now add the new menu anywhere on your site.

      <?php
      wp_nav_menu( array(
      'theme_location' => 'my-custom-menu',
      'container_class' => 'custom-menu-class' ) );
      ?>

      Most probably, you’ll want to place this code in the header.php file. This will place the menu at the very top of your site.

      7. Customize Your Excerpts

      Excerpts are short sample descriptions of your posts that you can display on your homepage or blog feed. By default, all excerpts have the same length and link text, but you can change that.

      First, let’s alter the text of the link that takes you from the excerpt to the full post. This is usually “Read more” or “Continue reading,” but you can make it whatever you want by pasting the following snippet into your functions file:

      function new_excerpt_more($more) {
      global $post;
      return '<a class="moretag" href="'. get_permalink($post->ID) . '"> Read the full article...</a>';
      }
      add_filter('excerpt_more', 'new_excerpt_more');

      Here, the link text has been set to Read the full article…

      customize WordPress excerpts by editing the functions.php file

      Then, let’s change the length of the excerpt. Paste this code into your functions file:

      function new_excerpt_length($length) {
      return 20;
      }
      add_filter('excerpt_length', 'new_excerpt_length');

      By default, the standard length is 55 words. However, in this example, it’s been set to 20. You can change the number to whatever you wish.

      8. Generate a Random Background to Your Site

      Finally, let’s end with a fun design trick. This tweak lets you randomly generate a new background color for your site every time somebody visits it. Start by adding the following code to the functions file:

      function wpb_bg() {
      $rand = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f');
      $color="#".$rand[rand(0,15)].$rand[rand(0,15)].$rand[rand(0,15)].
      $rand[rand(0,15)].$rand[rand(0,15)].$rand[rand(0,15)];
      echo $color;
      }

      This code generates the HTML tag for the colors, so all you need to do now is to make sure it gets applied to the page. To do that, you’ll need to find the <body> tag, which should look like this:

      <body <?php body_class(); ?>>

      This is usually in the header.php file but can be elsewhere, depending on your theme. When you’ve located the right line, simply replace it with the following code:

      <body <?php body_class(); ?> style="background-color:<?php wpb_bg();?>">>

      Save your file and open your website. You should see that it has a new background color:

      create random background colors on reload by editing your WordPress functions.php file

      Reload the page, and you’ll see a new color every time:

      create random background colors on reload by editing your WordPress functions.php file

      This is obviously not the right design choice for every site, but it’s a neat trick for some!

      Edit Your functions.php File

      The WordPress functions.php file is the perfect place to tinker with your site’s default functionality. It’s a powerful file that gives you a lot of control over your site once you understand how it works.

      Depending on your WordPress theme, you might be able to use the built-in Theme File Editor to access and edit your functions.php file. Otherwise, you can access it via FTP. Then, you can use custom code to do everything from displaying the estimated reading time of a post to customizing your excerpts.

      Do More with DreamPress

      DreamPress Plus and Pro users get access to Jetpack Professional (and 200+ premium themes) at no added cost!

      Managed WordPress Hosting - DreamPress



      Source link

      How to Mount a File System on Linux


      Mounting or unmounting a file system on Linux is usually straightforward, except when it isn’t. This article teaches you how to mount and unmount file systems, as well as list available and currently mounted file systems. It also explains how to handle the case where file systems won’t unmount because they are in use.

    • You can list the currently mounted file systems from a Linux command line with a simple mount command:

      mount
      

      The following is on an Ubuntu 22.04 LTS Linode, logged in as root:

      sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
      proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
      udev on /dev type devtmpfs (rw,nosuid,relatime,size=441300k,nr_inodes=110325,mode=755,inode64)
      devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)
      tmpfs on /run type tmpfs (rw,nosuid,nodev,noexec,relatime,size=99448k,mode=755,inode64)
      /dev/sda on / type ext4 (rw,relatime,errors=remount-ro)
      securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)
      tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev,inode64)
      tmpfs on /run/lock type tmpfs (rw,nosuid,nodev,noexec,relatime,size=5120k,inode64)
      cgroup2 on /sys/fs/cgroup type cgroup2 (rw,nosuid,nodev,noexec,relatime,nsdelegate,memory_recursiveprot)
      pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime)
      bpf on /sys/fs/bpf type bpf (rw,nosuid,nodev,noexec,relatime,mode=700)
      systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=29,pgrp=1,timeout=0,minproto=5,maxproto=5,direct,pipe_ino=18031)
      hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime,pagesize=2M)
      mqueue on /dev/mqueue type mqueue (rw,nosuid,nodev,noexec,relatime)
      debugfs on /sys/kernel/debug type debugfs (rw,nosuid,nodev,noexec,relatime)
      tracefs on /sys/kernel/tracing type tracefs (rw,nosuid,nodev,noexec,relatime)
      fusectl on /sys/fs/fuse/connections type fusectl (rw,nosuid,nodev,noexec,relatime)
      configfs on /sys/kernel/config type configfs (rw,nosuid,nodev,noexec,relatime)
      none on /run/credentials/systemd-sysusers.service type ramfs (ro,nosuid,nodev,noexec,relatime,mode=700)
      tmpfs on /run/user/0 type tmpfs (rw,nosuid,nodev,relatime,size=99444k,nr_inodes=24861,mode=700,inode64)
    • You can list the static file system information by displaying /etc/fstab:

      cat /etc/fstab
      

      The two static file systems for this instance are the root disk and the swap disk:

      # /etc/fstab: static file system information.
      #
      # Use 'blkid' to print the universally unique identifier for a
      # device; this may be used with UUID= as a more robust way to name devices
      # that works even if disks are added and removed. See fstab(5).
      #
      # <file system> <mount point>   <type>  <options>       <dump>  <pass>
      /dev/sda        /               ext4    errors=remount-ro 0     1
      /dev/sdb        none            swap    sw                0     0
    • You can also list and search for file systems using the findmnt command:

      findmnt
      

      The basic output shows the file system tree:

      TARGET                                SOURCE     FSTYPE     OPTIONS
      /                                     /dev/sda   ext4       rw,relatime,errors=remount-ro
      ├─/sys                                sysfs      sysfs      rw,nosuid,nodev,noexec,relatime
      │ ├─/sys/kernel/security              securityfs securityfs rw,nosuid,nodev,noexec,relatime
      │ ├─/sys/fs/cgroup                    cgroup2    cgroup2    rw,nosuid,nodev,noexec,relatime,nsdelegate,memory_recursiveprot
      │ ├─/sys/fs/pstore                    pstore     pstore     rw,nosuid,nodev,noexec,relatime
      │ ├─/sys/fs/bpf                       bpf        bpf        rw,nosuid,nodev,noexec,relatime,mode=700
      │ ├─/sys/kernel/debug                 debugfs    debugfs    rw,nosuid,nodev,noexec,relatime
      │ ├─/sys/kernel/tracing               tracefs    tracefs    rw,nosuid,nodev,noexec,relatime
      │ ├─/sys/fs/fuse/connections          fusectl    fusectl    rw,nosuid,nodev,noexec,relatime
      │ └─/sys/kernel/config                configfs   configfs   rw,nosuid,nodev,noexec,relatime
      ├─/proc                               proc       proc       rw,nosuid,nodev,noexec,relatime
      │ └─/proc/sys/fs/binfmt_misc          systemd-1  autofs     rw,relatime,fd=29,pgrp=1,timeout=0,minproto=5,maxproto=5,direct,pipe_ino=18031
      ├─/dev                                udev       devtmpfs   rw,nosuid,relatime,size=441300k,nr_inodes=110325,mode=755,inode64
      │ ├─/dev/pts                          devpts     devpts     rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000
      │ ├─/dev/shm                          tmpfs      tmpfs      rw,nosuid,nodev,inode64
      │ ├─/dev/hugepages                    hugetlbfs  hugetlbfs  rw,relatime,pagesize=2M
      │ └─/dev/mqueue                       mqueue     mqueue     rw,nosuid,nodev,noexec,relatime
      └─/run                                tmpfs      tmpfs      rw,nosuid,nodev,noexec,relatime,size=99448k,mode=755,inode64
        ├─/run/lock                         tmpfs      tmpfs      rw,nosuid,nodev,noexec,relatime,size=5120k,inode64
        ├─/run/credentials/systemd-sysusers.service
        │                                   none       ramfs      ro,nosuid,nodev,noexec,relatime,mode=700
        └─/run/user/0                       tmpfs      tmpfs      rw,nosuid,nodev,relatime,size=99444k,nr_inodes=24861,mode=700,inode64
    • You can restrict the output various ways, as described in man findmnt, to show only specific devices, mount points, or file system types, such as:

      findmnt -t ext4
      

      This lists only ext4 file systems:

      TARGET SOURCE   FSTYPE OPTIONS
      /      /dev/sda ext4   rw,relatime,errors=remount-ro
    • If you’re only interested in block devices, you can list them with lsblk:

      lsblk
      

      Once again, this only lists our Linode’s root and swap disks:

      NAME MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
      sda    8:0    0 24.5G  0 disk /
      sdb    8:16   0  512M  0 disk [SWAP]
    • You can mount file systems for a single session using the mount command, and permanently by editing /etc/fstab. Mounting needs to be done by an administrator, either by logging in as root or by using the sudo command. There are some cases where mounting is done automatically, like when you insert a USB flash drive. Here are a few examples using the mount command, plus the preparatory mkdir command to create the mount point.

      Most modern distros automatically mount USB drives when you insert them.

      The network file system (NFS) supports mounting remote file systems as shares for local access.

      You can add the -l (lazy) switch to umount to instruct the system to unmount the device when it’s free. Alternatively, the -f (force) switch makes the system unmount the device right away, at the possible risk of corrupting the file system. The -f switch is primarily intended to unmount unreachable NFS shares.

      Mounting a file system on Linux is generally a straightforward two-step process: create a mount point directory, and use the mount command to mount the device at the mount point. Unless the file system is in use, unmounting is even simpler, requiring only the umount command. File system mounting and unmounting requires you to be logged in as root, or use the sudo prefix to temporarily take on root privileges.

      You may wish to consult the following resources for additional information
      on this topic. While these are provided in the hope that they will be
      useful, please note that we cannot vouch for the accuracy or timeliness of
      externally hosted materials.



      Source link