LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 02-16-2013, 03:21 AM   #1
yashfire007
Member
 
Registered: Jan 2013
Distribution: CentOS, RHEL 6.4
Posts: 79

Rep: Reputation: Disabled
Setting password to read a file


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.
 
Old 02-16-2013, 04:39 AM   #2
fortran
Member
 
Registered: Nov 2011
Location: Cairo, Egypt
Distribution: CentOS, RHEL, Fedora
Posts: 300
Blog Entries: 2

Rep: Reputation: 51
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
 
Old 02-16-2013, 04:50 AM   #3
yashfire007
Member
 
Registered: Jan 2013
Distribution: CentOS, RHEL 6.4
Posts: 79

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by pavi_kanetkar View Post
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.
 
Old 02-16-2013, 07:04 AM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,369

Rep: Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753
Explain why you are trying to do this; cat does not have an option for this http://linux.die.net/man/1/cat
 
Old 02-17-2013, 11:06 PM   #5
fortran
Member
 
Registered: Nov 2011
Location: Cairo, Egypt
Distribution: CentOS, RHEL, Fedora
Posts: 300
Blog Entries: 2

Rep: Reputation: 51
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.
 
Old 02-17-2013, 11:13 PM   #6
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
It can be protected with a password using mcrypt, as:
Code:
[user@localhost]~$ mcrypt sample.txt
For further details, once check here.
 
Old 02-18-2013, 07:45 PM   #7
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
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.

--- rod.
 
Old 02-18-2013, 08:49 PM   #8
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
Quote:
Originally Posted by theNbomr View Post
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Ubuntu 11.10 has a read-only file system. Been trying to recover password to no avail xric Linux - Newbie 1 11-09-2012 06:58 PM
Read password from AES encryption from txt file dolphs Linux - Security 5 01-19-2011 04:10 PM
[SOLVED] Installed newest Ubuntu setting a weak password. Changed password now buggered? lugoteehalt Ubuntu 1 05-29-2010 09:51 PM
How to read password protected power point file tanveer Linux - General 8 10-22-2009 02:47 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:53 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration