قالب وردپرس درنا توس
Home / Tips and Tricks / How to secure your Linux system

How to secure your Linux system



  External hard drive connected to laptop via USB
Yuriy Seleznev / Shutterstock.com

No data loss. Secure your valuable data via the Linux command line. We use the command rsync for this and have even found some nice optional graphical interfaces for it.

There are many ways to back up your files. We wanted to show you a robust, flexible and reliable way to protect your data. We've selected rsync because it has well-known algorithms that calculate the differences between files in the source and destination directories. Only the differences between two versions of a file are transferred, not the entire file, if this can be avoided.

If this efficiency goes along with the solid track record of performing file copies and directory synchronization since the mid-nineties, rsync is a perfect candidate for backing up from the Linux command line.

In addition, there are independent software programs that act as a front-end to rsync . They provide graphical user interfaces (GUIs) for rsync which may be easier for some users to use.

The easier and faster a backup can be performed, the more likely it is. [1

9659008] Using rsync with an External Hard Drive

To back up your data to an external hard drive, the hard drive must be enabled and accessible to you. If you can write on it, you can also rsync . In this example, an external USB hard disk named SILVERXHD (for "Silver eXternal Hard Drive") is connected to the Linux computer. It was automatically provided by the operating system.

You must know the path to the drive. In GNOME, open the Nautilus File Browser and locate the name of the drive in the sidebar.

Hover the mouse over the name of the external drive, and a tooltip will show you the path to the drive.

 Tooltip for an external drive

In this example, the tooltip tells us that the mount point for the file system on the external drive is "/ media / dave / SILVERXHD". Navigate to the external drive Drive and open a terminal window there. Use the command pwd to print the path to the terminal window.

Copying content from the source directory

Use rsync to copy the contents of a directory into it Use the following command as the backup destination:

Option -r (recursive) causes rsync to copy all nested subdirectories and their contents. Note that at the end of the word "SILVERXHD" there is a slash "/", but it will be broken in the next line of the screenshot.

  rsync -r / home / dave / Documents / / media / dave / SILVERXHD / 

  rsync -r / home / dave / Documents / / media / dave / SILVERXHD / in a terminal window

The File copy is executed and you are returned to the command prompt. [19659004] If we look at the external USB drive, we see that the directories in the Documents directory have been copied to the root of the external drive.

  ls 

  ls in a terminal window

Copy The source directory and its contents

If you wanted to copy the document directory and to the external drive, remove the " / "at the end of" / home / dave / Documents ". at the command line as follows:

  rsync -r / home / dave / documents / media / dave / SILVERXHD / 

  rsync -r / home / dave / documents / media / dave / SILVERXHD / in a terminal window

To avoid confusion, I removed the two previously copied directories from the external drive before executing this second command.

When we finish the second copy and look at the external drive again, let's look at that, see the Documents directory has been copied. The content is in this directory. You are not in the root directory of the external drive.

 ls in a terminal window

Copy to a specific destination directory

Add the following to copy to a specific directory on the target disk The name of the directory to the destination path. Suppose we want to copy the contents of the / home / dave / Documents directory to a directory called backups on the external drive.

We do this with the following command.

  rsync -r / home / dave / Documents / / media / dave / SILVERXHD / backups / 

  rsync -r / home / dave / Documents / / media / dave / SILVERXHD / backups / na terminal window

On the external drive, we see that the backup directory has been created, and this directory contains the contents of the / home / dave / Documents directory.

  ls 
  ls-fuses 

  ls output in a terminal window

Keeping file ownership and permissions

Use the -a (archive) option to Keep file attributes such as modification date, file ownership, access permissions, etc. for copied files. Symlinks and special block files.

  rsync -ra / home / dave / Documents / / media / dave / SILVERXHD / backups / 

  rsync -ra / home / d ave / Documents / / media / dave / SILVERXHD / backups / in a terminal window

Using Verbose Mode

The option -v (verbose) forces rsync to list the files to be copied.

  rsync -rav / home / dave / Documents / / media / dave / SILVERXHD / backups / 

  rsync -rav / home / dave / Documents / / / media / dave / SILVERXHD / backups / in a terminal window

When the copy is complete, a summary of the backup appears.

 Detailed output of rsync in a terminal window

  • Sent : The bytes transferred to the destination.
  • Receive : The bytes received at the host.
  • Bytes / sec : is the effective transmission rate.
  • Total Size : Represents the size of the data that would have been sent if you had not used rsync . On subsequent runs of rsync only the file differences are transferred. This number represents the data that did not need to be transmitted .
  • Acceleration : This is the ratio between the amount of data that had to be sent and the total amount of data that was transmitted there. If rsync needs to completely copy all the files (for example, the first time you run them), the speed is 1.0. The next use of rsync will optimize the transfers. Only the differences between the files are sent, not the entire files. Files without changes are ignored. The acceleration count represents the ratio between the small amount of data that needed to be transferred and the total size of the files.

Using the Progress option

The option -P (progress) Causes rsync generates a small progress report after copying each file.

  rsync -raP / home / dave / Documents / / media / dave / SILVERXHD / backups / 

  rsync -raP / home / dave / Documents / / media / dave / SILVERXHD / backups / in a terminal window

The information provided can be viewed between each copied file.

 rsync output with progress in a terminal window

The information provided is:

  • byte size : data transferred for this file.
  • Percentage : Percentage of transferred files.
  • B / s : data transfer rate.
  • Remaining time : Estimated time remaining to transfer this file.
  • xfr # : The number of transferred files. Previous error.
  • to-chk : The number of files that must be verified and verified by the optimization algorithms (compression) option. This compresses the file during the transfer, but does not save the file compressed in the destination directory.

    The compression option does not provide significant benefits for many small file transfers. For collections of larger files, this can significantly reduce transmission time.

    We also use the option - partially . rsync deletes partially transmitted files caused by network errors or other interruptions. The option - partial forces rsync to leave the partially transferred files on the target. When the net time rsync is executed, the parts of the partially transferred files do not have to be retransmitted.

    Note that you may not want to use this option if there is a risk of someone confusing the file. Partially transferred files for completely transferred files.

      rsync -ravz --partial / home / dave / Documents / / media / dave / SILVERXHD / backups / 

      rsync -ravz --partial / home / dave / Documents / / / media / dave / SILVERXHD / backups / in a terminal window

    In our example, the benefits are marginal.

     rsync output in a terminal window

    The acceleration ratio has been improved but by two hundredths of a percent! In a real-world scenario, your speed improvements are more impressive.

    Using rsync over a network

    So far, we have selected an external USB drive as the destination. Use the path to this location on the command line to use a network location as the backup destination. The network examined in this article has a Network Attached Storage Device (NAS).

    You can use the same trick as before to determine the path to the NAS by hovering over the connection to this device in Nautilus.

    There are no special options for backing up in a network. These are all options we have already used.

      rsync -ravz --partial / home / dave / Documents / / media / dave / NAS / dave / backups / 

      rsync -ravz --partial / home / dave / Documents / / media / dave / NAS / dave / backups / in a terminal window

    There is no difference in the format of the output.

     rsync output in a terminal window [19659004] Not surprisingly, the number of bytes / sec improves significantly.

    If we run rsync again, we can see that no files need to be transferred because no changes have been made. However, some bytes are still being transferred back and forth. This is the amount of data that must be transferred to compare the file list on the destination with the file list on the source.

     Output of rsync without files to be transferred in a terminal window

    The acceleration ratio is an order of magnitude better in this case. In practice, your performance ratios are somewhere between our two pseudo-artificial readings.

    Using rsync over SSH

    rsync supports backing up over an SSH connection. We need to specify the name of the user account and the SSH location on the command line. We use a network name here, but you can also use an IP address.

    Note the ":" between the SSH connection details and the start of the network path on the remote destination.

      rsync -ravz - -partial / home / dave / Documents / dave@sulaco.local: /home/dave/backups/ 

      rsync -ravz --partial / home / dave / Documents / dave@sulaco.local : / home / dave / backups / in a terminal window

    You will be asked for the password of the user account on the remote computer . This is not your password on the source computer.

     Rsync over an SSH connection in a terminal window

    The backup is completed as usual. Throughput is not as high as a normal network connection due to the encryption and decryption that takes place in the secure shell connection.

    Automating Your Backups

    By adding entries to your crontab file, we can easily create automated backups.

      crontab -e 

      crontab -e in a terminal window

    We set up an automatic backup that runs every day at 4:30 (if the computer is on at that time) course) , The syntax for the command rsync does not change at all.

     crontab open in nano in a terminal window

    Ctrl + O writes your changes to the file. and Ctrl + X close the editor nano .

    RELATED: Scheduling Tasks on Linux: An Introduction to Crontab Files

    Putting a Friendly Face on Rsync

    Persons less familiar with the command line , can use one of several programs that set a graphical user interface to rsync . Two good examples are luckyBackup and Grsync. In both programs, many of the rsync options can be selected through the user interface.

    The Grsync program focuses on being a visual wrapper for rync . , It provides easy access to the options rsync and adds only a limited set of new functions.

      One of the Grsync Settings Dialogs,
    One of the Grsync Settings Dialogs,

    The [19459009ProgramLuckyBackup is much more than a simple wrapper for rsync . It is a backup program used behind the scenes rsync . For example, luckyBackup can create multiple "snapshots" of your backup. You can then return to the versions of the files in each of the snapshots.

      One of the luckyBackup settings dialogs
    One of the luckyBackup settings dialogs

    How to Install Grsync

    Grsync in Ubuntu Use this command:

      sudo apt-get grsync install 

      sudo Install apt-get grsync in a Terminal Window

    How to Install Grsync Use the following command in Fedora:

      sudo dnf install grsync 

      sudo dnf install grsync [19659004] To install Grsync in Manaro use the following command:

      sudo pacmanc -Syu 

      sudo pacman -Syu grsync in a terminal window

    Installing luckyBackup

    To install luckyBackup in Ubuntu, use the following command:

      sudo apt-get lucky-install 

      sudo apt-install install luckybackup in a terminal window

    So ins install luckyBackup Use the following command in Fedora:

      sudo dnf install luckybackup 

      sudo dnf install luckyback in a terminal window

    In Manjaro you need luckyBackup from the Arch User Repository (AUR). You can do this with the package manager pamac .

     The package manager pamac "width =" 646 "height =" 350 "src =" /pagespeed_static/1.JiBnMqyl6S.gif "onload =" pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon (this); "onerror =" this. onerror = zero; pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon (this);

    Do not risk it, backup your data. Backups are absolutely important. Secure frequently, in many places and on different media. Once set up, rsync can do all this for you.




Source link