author avatar
    Senior Product Manager
 

Summary
Files of hardware and software can be shared among different users in Linux system. If one user want to access a file which is using by another one, Linux will lock the file to prevent conflits. Here, we will introduce how to lock file in Linux.



Part 1: What is Linux

Similar to Unix, Linux is a free and open source operating system. Generally, Linux will be distributed as released version for personal computer and service, which includes kernel and database as well as many other software. Since Linux is a freeware, any user can create their own Linux according to their needs.
what is linux

Part 2: Reasons of Locking Files in Linux

Two main reasons of locking files in Linux could be:

1. To avoid two or more progress accessing the same file. If not, data lose could happen.

2. To prevent unauthorized access.

Here we will go a little further on the first reason. In a multitasking operating system environment, if a program want to access a file which is used by another program, the running program could get some damaged or incomplete data. If two programs access and modify a same file, the file could be damaged. In order to solve this problem, a mechanism, file lock, is designed to solve this problem.

If you are using Windows, encryption software Renee SecureSilo and Renee File Protector) can help you.
Hot Topic - ADsBest Partner for Data Protection - Encrypt Files and Prevent Unauthorized Data Copy Best Partner for Data Protection - Encrypt Files and Prevent Unauthorized Data Copy

Quick encryption Encrypt files in virtual disk promptly and support to save files at any time.

Easy to use Support to hide itself in safe, simple operation on the clear interface.

Control data transfer Support to set white list and disable USB ports, network, CD

Well protection Utilize the AES256 algorithms and support to encrypt various files in the private format.

Comprehensive play for encryption Protect USB devices and password wallet; hide/disguise files; support to record operations on USB.

Quick encryption Encrypt files in virtual disk promptly and save files at any time.

Easy to use Support to hide itself in safe, simple operation on the clear interface.

Well protection Utilize the AES256 algorithms and support to encrypt various files in private format.

For Details

Part 3: How to Lock Files in Linux

(Lock) Command Line – Linux Chattr

Being one of the commands in Linux, Chattr can change the attributes of Linux files. It can also be used to change the attributes of files and folders saved in ext2 system.
The following 8 modes are available:
a: Provide append-only permission to a file or folder
b: Do not update the accessed date of files or folders
c: Save files/folders after compressed
d: No dump
i: Immutable
s: Secure deletion
S: Synchronous updates
u: Undeletable
Syntax of Chattr:
chattr [ -RVf ] [ -v version ] [+/-/=][file or folder…]
Description:
• -R recursively lists attributes of directories and their contents
• -v <version no.> set the version of file or folder.
• -V displays the program version.
• +<attributes> Enable target attribute for directory or file
• -<attributes> Disable target attribute for directly or file
• =<attributes> Specify target attribute for directly or file
Command Demonstration:
• [root@w zdw]# chattr +a test.sh
• [root@w zdw]# rm -f test.sh
• rm: cannot remove `test.sh’: Operation not permitted
• [root@w zdw]# echo 11 >>test.sh
• [root@w zdw]# echo 11 >>test.sh
• [root@w zdw]# echo 11 >test.sh
• -bash: test.sh: Operation not permitted
• [root@w zdw]# lsattr test.sh
• —–a——-e- test.sh
Locking key system files can upgrade system security. Here are some files locked with chattr:
• chattr +i /etc/passwd file
• chattr +i /etc/shadow password protected file
• chattr +i /etc/group group file
• chattr +i /etc/gshadow main password file
• chattr +i /etc/inittab important system boot files

(Lock) Nautilus

Being a command in Linux, Nautilus will open a window with terminal location with root authority. Users can manage, delete or add files inside the current folder.
Following is detailed steps of locking files with Nautilus:
1. Right-click the target file, and select [Compress] in the menu. Then set the password.
lock linux file with nautilus
2. Then you will receive the notification of compressing successfully.
lock linux file with nautilus
How to unlock the file?
1. Click the Lock icon around the target file and then enter the password in the pop up window.
lock linux file with nautilus
2. File will be unlocked after entering the correct password.
unlock files in linux

(Encrypt) Ccrypt

Using Rijndael cipher, Ccrypt, a tool to encrypt and decrypt files , is using AES encryption standard and provide great safety. The encryption and decryption both relies on the keywords that users offer. In default, system will ask users to type the keywords n terminal which ensure the safety.
lock linux file with ccrypt

(Encrypt) Openssl

Openssl, a command line tool, is for encrypting message and files on Internet. It is also used for secure communication and has been widely spread on webpage server.
lock linux file with openssl

Password Management in Linux

The algorithm of the key is public. The security of data relies on the confidentiality of the key instead of the algorithm.
Symmetric encryption: key can be used to decrypt at the same time. Generally, the key will be included in the encryption code, which enlarge the possibility of cracking. Besides, the administrator can get access to the key and then find out the password. So, the key should be kept in confidential way. As a result, the key should be set privately and transmit in a safe way.
Asymmetric encryption: The security of password is equal to that of the key. The plaintext of the password is encrypted with the public key. If users want to restore the original password, corresponding private key is necessary. In other words, users need to ensure the security of the private key to protect the password.

Summary

Methods of locking Linux files has been listed above. Windows is still one of the most popular computer system. If you want to lock files in Windows, data security software (Renee SecureSilo and Renee File Protector) are recommended.