Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
How to set password if we are trying to read a file by cat ,it should ask for password after we have given the password it should display the contents of the file.
i need is to prompt for password if we try to use cat over a file.
If it is possible, please tell me what have to be done for the same.
To encrypt the file
$gpg -c /path/of/the/file
It will create a encrypted file as .gpg
to decrypt the file
$gpg /path/of/the/gpg/file.gpg
Brother thank you for your reply. But actually what i need is if i need to display file by cat command it should ask for password prompt. How can set this. If possible please tell me.
When you use gpg command to encrypt a file, it makes encrypted copy of a file.
Now you try to open original file, it throws garbage character on terminal.
Remove this original file from the directory where encrypted file is placed because when you decrypt it, it overwrites encrypted copy and it can create problem to open it.
If you try to read the .gpg file, it shows garbage character too because it is encrypted.
If you rename it using $ mv and again try to read it, it shows garbage character.
If you want to read the file, you have to decrypt.
Code:
$ gpg filename.gpg
Now it makes original copy of your file and you can read this.
There are a gzillion ways to display a file. If you somehow removed all of the tools that can read a file, or modified them to do what you want, it would still be trivial to create a program that would be able to read the file. To make a file unviewable, you will want to use proper file permissions and ownerships.
There are a gzillion ways to display a file. If you somehow removed all of the tools that can read a file, or modified them to do what you want, it would still be trivial to create a program that would be able to read the file. To make a file unviewable, you will want to use proper file permissions and ownerships.
Agree with Nbomr. Instead of using an encryption or password protection tool without assuring that it will work, you should better go with the concept of file access permissions. Simply create a group and add it as main group of the file and give the group read/write permissions. Then add only those users to this group whom you want to give read permission on that file.
Code:
~$ ls -l sample.txt
-rwxrwx--- user newgroup sample.txt
On the other hand, you can go with ACLs, which will be little complicate but will work perfectly.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.