Files inside a RAR archive can have important data. So you may want to protect it from the unusual access. In Linux, the rar command provides a feature to set the password on rar archives. I already discussed to create a rar archive in Linux in a post. In this article, we will show you how to set a password on a RAR archive.
What are RAR archives?
Like other archives, a RAR file is a data container that stores one or several files in compressed form. RAR is a proprietary file format which is developed by Eugene Roshal. It is a native file format for the WinRAR archiver. RAR file uses
.rar file extension. WinRAR application is not available for Linux we can use the rar program to create, extract or set the password in a RAR file.
Creating RAR archives
I already discussed it in a previous article but for the sake of completeness of this article, We will also create a rar file here. I have a directory named sample which contains some files inside it. To create sample.rar file from sample directory we will use the following command in the terminal –
rar a sample.tar sample
The output of this command will be something like given in the below image –
Now if it shows that the rar program is not installed in your system then first use the following command to install it and then again run the above command –
To install rar on Debian/Ubuntu/LinuxMint use –
sudo apt install rar
Or if you are using an rpm-based distribution then use –
sudo yum install rar
To install it in Fedora use –
sudo dnf install rar
Set the password on a RAR archive
This is a very useful feature of the rar tool in Linux. It allows us to set a password on an archive file. Use the options a and -p with the rar command to create a password protected rar file. Now execute the following command in your terminal –
rar a -p sample.rar sample
This will prompt you to enter the password, enter it, It will ask to enter it again. Now once you press the enter the password will be set on that file.
There are a lot of options available that you can use with the rar command. You can see the manual page of the rar for more details. Now if you want to say something on this topic then write your thoughts in the comments below.