password protected folders?

General discussion Forum. All YDL related question which are not Install or Beginner questions.

password protected folders?

Postby Iguana » 29 Jun 2010, 03:01

I was wondering how would I password protect a folder that has spaces in the folder's name?
For instance...

If I do this:
Code: Select all
[simeon92@computer ~]$ su -
Password:
[root@computer ~]# chown -R root:root /home/simeon92/Desktop/MY DOCUMENTS

This is what I get:
Code: Select all
chown: cannot access `/home/simeon92/Desktop/MY': No such file or directory
chown: cannot access `DOCUMENTS': No such file or directory
[root@computer ~]#

And if I do this:
Code: Select all
[root@computer ~]# chmod 700 /home/simeon92/Desktop/MY DOCUMENTS

This is what I get:
Code: Select all
chmod: cannot access `/home/simeon92/Desktop/MY': No such file or directory
chmod: cannot access `DOCUMENTS': No such file or directory
[root@computer ~]#

It wont let me root and protect my folder!!!

Also, lets try a folder with no spaces:
Code: Select all
[root@computer ~]# chown -R root:root /home/simeon92/Desktop/EMULATION
[root@computer ~]#

It works!!!

And this:
Code: Select all
[root@computer ~]# chmod 700 /home/simeon92/Desktop/EMULATION
[root@computer ~]#

It works again, because this is what error I get when I try to open it:
Code: Select all
The folder contents could not be displayed.
You do not have the permission nessary to
view the contents of "EMULATION".

To change back the permissions for myself do this:
Code: Select all
[root@computer ~]# chmod 777 /home/simeon92/Desktop/EMULATION
[root@computer ~]#

And this:
Code: Select all
[root@computer ~]# chown -R simeon92:simeon92 /home/simeon92/Desktop/EMULATION
[root@computer ~]#


Soo, I'm guessing I can't protect a folder that has spaces in it...
Why can't I do this? :roll:

If there is a way please do tell..

One more thing, how do I access a rooted protected folder, without changing back the permissions?
PS3 CECHLO1
GNOME Desktop
Yellowdog Linux 6.2
ihome keyboard
ihome gaming mouse (red)
Iguana
ydl addict
ydl addict
 
Posts: 121
Joined: 01 Apr 2010, 22:49
Location: Florida

Re: password protected folders?

Postby ppietro » 29 Jun 2010, 06:01

Iguana wrote:I was wondering how would I password protect a folder that has spaces in the folder's name?

If there is a way please do tell..


You need to escape the spaces. Generally, you do that with a backslash (i.e. \)

So - in Unix - a name with an escaped space would look like this:

Code: Select all
My\ Documents


NOTE: You can always use the TAB key to auto-complete names with spaces. So - as an example, if you had a folder on your desktop called "My Documents", you could start by typing:

Code: Select all
cd ~/Desktop/My


then hit the TAB key. The bash shell will autocomplete the command:

Code: Select all
cd ~/Desktop/My\ Documents


Iguana wrote:One more thing, how do I access a rooted protected folder, without changing back the permissions?


Well - normally you'd use the terminal window with the su command. But - I don't think that's exactly what you're asking. I think the question you're asking is: "From the GUI, logged in as a normal user, how do I open a folder that's been assigned to root user?"

Well - the only real way is to log off as the normal user, and re-login as root. This obviously isn't what you really want to do.

See - the deal is that Unix doesn't really have the concept of a password protected folder. Instead, unix has the concept of access permissions for folders.

What you would normally do is create a separate user account for everyone on your system. Then, use the access permissions to customize access to folders based on that login. You can do this with the chmod command.

Here's an example.

Let's say you have a user "fred". You want to allow folks to see into fred's home directory and into a sub-folder named f_public, but not into a folder called f_private. In addition, you want full write permissions for f_public

So - as root - here's the content of my /home directory:

Code: Select all
[root@localhost home]# ls -al
total 16
drwxr-xr-x   4 root  root  4096 Jun 28 22:27 .
drwxr-xr-x  26 root  root  4096 Jun 28 22:07 ..
drwx------   3 fred  fred  4096 Jun 28 22:27 fred
drwx------ 110 paulp paulp 4096 Jun 28 22:16 paulp
[root@localhost home]#


So - to allow others to see fred's directory, use chmod a+rwx This allows all to look in the directory:
Code: Select all
[root@localhost home]# chmod a+rwx fred
[root@localhost home]# ls -al
total 16
drwxr-xr-x   4 root  root  4096 Jun 28 22:27 .
drwxr-xr-x  26 root  root  4096 Jun 28 22:07 ..
drwxrwxrwx   5 fred  fred  4096 Jun 28 22:35 fred
drwx------ 110 paulp paulp 4096 Jun 28 22:16 paulp
[root@localhost home]#


NOTE: We don't want to do this for every folder in /home/fred, so we leave out the -R

Now, let's create the f_private and f_public folders. We'll use the su command from root to temporarily become fred:

Code: Select all
[root@localhost home]# su fred
[fred@localhost home]$ cd fred
[fred@localhost ~]$ mkdir f_public
[fred@localhost ~]$ mkdir f_private
[fred@localhost ~]$ ls -al
total 36
drwxr--r-- 5 fred fred 4096 Jun 28 22:32 .
drwxr-xr-x 4 root root 4096 Jun 28 22:27 ..
-rw------- 1 fred fred    8 Jun 28 22:31 .bash_history
-rw-r--r-- 1 fred fred   33 Jun 28 22:27 .bash_logout
-rw-r--r-- 1 fred fred  176 Jun 28 22:27 .bash_profile
-rw-r--r-- 1 fred fred  124 Jun 28 22:27 .bashrc
drwxrwxr-x 2 fred fred 4096 Jun 28 22:32 f_private
drwxrwxr-x 2 fred fred 4096 Jun 28 22:32 f_public
drwxr-xr-x 4 fred fred 4096 Jun 28 22:27 .mozilla
[fred@localhost ~]$


Note that f_private and f_public have full access rights for user, group, and read/execute access for other. So - let's remove read, write & execute permissions from f_private for group & others and add write permissions for others to f_public:

Code: Select all
[fred@localhost ~]$ chmod -R go-rwx f_private
[fred@localhost ~]$ chmod -R o+w f_public/
[fred@localhost ~]$ ls -al
total 36
drwxrwxrwx 5 fred fred 4096 Jun 28 22:46 .
drwxr-xr-x 4 root root 4096 Jun 28 22:27 ..
-rw------- 1 fred fred  189 Jun 28 22:36 .bash_history
-rw-r--r-- 1 fred fred   33 Jun 28 22:27 .bash_logout
-rw-r--r-- 1 fred fred  176 Jun 28 22:27 .bash_profile
-rw-r--r-- 1 fred fred  124 Jun 28 22:27 .bashrc
drwx------ 2 fred fred 4096 Jun 28 22:35 f_private
drwxrwxrwx 2 fred fred 4096 Jun 28 22:46 f_public
drwxr-xr-x 4 fred fred 4096 Jun 28 22:27 .mozilla
[fred@localhost ~]$ 


Now - only fred has access to f_private, but everyone has full access f_public.

Let's test this. I'll open a new terminal window as myself:
Code: Select all
paulp@localhost ~]$ cd /home/fred
[paulp@localhost fred]$ ls
f_private  f_public
[paulp@localhost fred]$ cd f_public
[paulp@localhost f_public]$ ls
[paulp@localhost f_public]$ cd ..
[paulp@localhost fred]$ ls
f_private  f_public
[paulp@localhost fred]$ cd f_private
bash: cd: f_private: Permission denied
[paulp@localhost fred]$


No passwords required. Fred can access both folders - and I - paulp - can only access /home/fred & /home/fred/f_public. This works for the terminal window and for the GUI as well.

If you need more control, you would use the group parameter and set up groups that have shared access.

Cheers,
Paul

P.S. Root user is special. You normally don't use root for day to day computing. Instead, you use that account for system administrative functions. So - assigning a folder to root on your normal login desktop is not the standard way to protect your folder.
User avatar
ppietro
Site Admin
Site Admin
 
Posts: 4965
Joined: 13 Sep 2007, 22:18

Re: password protected folders?

Postby Iguana » 29 Jun 2010, 19:06

ppietro wrote:
Iguana wrote:I was wondering how would I password protect a folder that has spaces in the folder's name?

If there is a way please do tell..


You need to escape the spaces. Generally, you do that with a backslash (i.e. \)

So - in Unix - a name with an escaped space would look like this:

Code: Select all
My\ Documents


NOTE: You can always use the TAB key to auto-complete names with spaces. So - as an example, if you had a folder on your desktop called "My Documents", you could start by typing:

Code: Select all
cd ~/Desktop/My


then hit the TAB key. The bash shell will autocomplete the command:

Code: Select all
cd ~/Desktop/My\ Documents


Iguana wrote:One more thing, how do I access a rooted protected folder, without changing back the permissions?


Well - normally you'd use the terminal window with the su command. But - I don't think that's exactly what you're asking. I think the question you're asking is: "From the GUI, logged in as a normal user, how do I open a folder that's been assigned to root user?"

Well - the only real way is to log off as the normal user, and re-login as root. This obviously isn't what you really want to do.

See - the deal is that Unix doesn't really have the concept of a password protected folder. Instead, unix has the concept of access permissions for folders.

What you would normally do is create a separate user account for everyone on your system. Then, use the access permissions to customize access to folders based on that login. You can do this with the chmod command.

Hey that's nice, thanks..

So I'll be doing this:
Code: Select all
MY\ DOCUMENTS

instead of this:
Code: Select all
MY DOCUMENTS

I tried it and it worked, no errors, thanks again!!!
ppietro wrote:P.S. Root user is special. You normally don't use root for day to day computing. Instead, you use that account for system administrative functions. So - assigning a folder to root on your normal login desktop is not the standard way to protect your folder.

Too bad that there isn't such things as a password protected folder in unix (It would have been easier), but either way it doesn't mater.. I guess the penguin knows best :D
Even though my method isn't standard, it is quite unique :mrgreen:
PS3 CECHLO1
GNOME Desktop
Yellowdog Linux 6.2
ihome keyboard
ihome gaming mouse (red)
Iguana
ydl addict
ydl addict
 
Posts: 121
Joined: 01 Apr 2010, 22:49
Location: Florida

Re: password protected folders?

Postby aguilarojo » 06 Jul 2010, 03:43

ppietro wrote:
Iguana wrote:I was wondering how would I password protect a folder that has spaces in the folder's name?

If there is a way please do tell..


You need to escape the spaces. Generally, you do that with a backslash (i.e. \)

So - in Unix - a name with an escaped space would look like this:

Code: Select all
My\ Documents


NOTE: You can always use the TAB key to auto-complete names with spaces. So - as an example, if you had a folder on your desktop called "My Documents", you could start by typing:

Code: Select all
cd ~/Desktop/My


then hit the TAB key. The bash shell will autocomplete the command:

Code: Select all
cd ~/Desktop/My\ Documents


Unix/Linux has a lot of features which are difficult to describe as these "tried and true" methods/strategies were developed to address problems which usually affect servers gone awry, not home computers. If you want to learn a bit more about those strategies and features it would be to your advantage to acquire one or two reference books on Unix or Linux System Administration. No two will address the same strategies which can be useful in expanding an understanding regarding the use of those approaches.

The advantage of the wild-card symbol (*) is that every Unix/Linux terminal understands it to mean any and all possible characters. The trick is to understand that although the human mind distinguishes between a number, letter and a symbol, the terminal sees everything as a character.

Let's return to your folder problem and complicate it a bit. Let's say you have, three different directories named:

  • My Documents
  • MY DO458n6tw
  • MY doc-43!f

I want to move them all from my home directory to the usr directory. Let's say I'm already within my home directory, how do I do that?

Code: Select all
$sudo mv ./M* /usr
Password:


The command is executed and all the directories I named above are moved to usr as I wished. The Password asked for by Linux is the user, not root password.

To get the sudo command to work properly distinct passwords for user and root modes must exist and be properly established within Linux. Using sudo is not the same as switching to root by using the root password; as the intention of switching to root is to engage upon more extensive tasks peculiar to a system administrator such as creating/removing directories on a hard drive; installing/removing applications and more which usually take more than a few brief minutes. The sudo command is for utilizing root level manipulations (such as moving directories or files across a hard-drive) for a brief period of time such that after that time has been exhausted one is immediately returned to user mode without any other action.

By the way, here's a question: Why does using the wild-card symbol work?
Answer: Spaces are considered by the terminal to be characters as well.

Just as an experiment, let's say My Documents exists in my home directory called cat and I'm located elsewhere say I'm in an invisible directory say .themes. How to get there using the wild card?

$cd ./.themes /home/cat/My*

Again, let's imagine that I've three different directories which start with My but only one contains 34_u and ends in t like all the rest. How to do that?

$cd ./.themes /home/cat/My*34*

The really neat thing about this is that because the terminal already understands * there is nothing special to do except use it.

Iguana wrote:
ppietro wrote:
Iguana wrote:One more thing, how do I access a rooted protected folder, without changing back the permissions?


Well - normally you'd use the terminal window with the su command. But - I don't think that's exactly what you're asking. I think the question you're asking is: "From the GUI, logged in as a normal user, how do I open a folder that's been assigned to root user?"

Well - the only real way is to log off as the normal user, and re-login as root. This obviously isn't what you really want to do.

See - the deal is that Unix doesn't really have the concept of a password protected folder. Instead, unix has the concept of access permissions for folders.

What you would normally do is create a separate user account for everyone on your system. Then, use the access permissions to customize access to folders based on that login. You can do this with the chmod command.

Hey that's nice, thanks..

So I'll be doing this:
Code: Select all
MY\ DOCUMENTS

instead of this:
Code: Select all
MY DOCUMENTS

I tried it and it worked, no errors, thanks again!!!
ppietro wrote:P.S. Root user is special. You normally don't use root for day to day computing. Instead, you use that account for system administrative functions. So - assigning a folder to root on your normal login desktop is not the standard way to protect your folder.

Too bad that there isn't such things as a password protected folder in unix (It would have been easier), but either way it doesn't mater.. I guess the penguin knows best :D
Even though my method isn't standard, it is quite unique :mrgreen:


Remember that in Unix/Linux it is rare that multiple approaches to resolve a problem or question don't exist. Exceptions regarding when one strategy or another applies will be discovered as one's experience with Linux/Unix becomes more complex. Let's move onto passwords.

Let's say that you've put some files into a directory/folder which you want to lock with a password so that you can send it within an email or via other means - put it on someone's portable drive for instance. Or let's say you want to encrypt a particular file. How do we do that?

There exists a program called GnuPG which allows someone to create not only passwords but utilize a variety of very powerful encryption strategies all designed to maintain privacy. Many different distributions include it but if you want the latest version you have to get it from the website and compile the source, and install it yourself. Hopefully, you are familiar with some aspects of the C language as that background is very useful in all aspects of Unix/Linux. Take the time to study the GnuPG manual in detail to actualize the variety of tools within this application. Files and folders encrypted by GnuPG are quite impervious to being opened by anyone other than the person whom you intended them for.

All the best...

Everything on the Earth has a purpose.
Every disease an herb to cure it.
And every person has a mission.
This is the Indian Theory of Existence.
-- Morning Dove, Salish (1888-1936)
User avatar
aguilarojo
ydl guru
ydl guru
 
Posts: 227
Joined: 06 May 2009, 14:50
Location: New York City


Return to General

Who is online

Users browsing this forum: No registered users and 31 guests

cron