TranslateProject/sources/tech/20140807 Command Line Tuesdays--Part Seven.md

3.8 KiB
Raw Blame History

Command Line Tuesdays Part Seven

Heya geekos. Ive checked the curriculum, and were at part 7 of 8 as of today. Which means there will be one more and sadly final CLT next tuesday. So for today, lets deal with some permissions!

As we all know, we can have many users using one machine. To protect the users from each other, permissions have been devised. And we have already discussed file permissions, so lets refresh our memories with a single click.

chmod

The chmod command is used for changing permissions on a directory or a file. To use it, you first type the chmod command, after that you type the permissions specification, and after that the file or directory youd like to change the permissions of. It can be done in more way, but mr Shotts focuses on the octal notation method.

Imagine permissions as a series of bits. For every permission slot thats not empty, theres a 1, and for every empty one theres a 0. For example:

rwx = 111

rw- = 110

etc.

And to see how it looks in binary:

rwx = 111 —> in binary = 7

rw- = 110 —> in binary = 6

r-x = 101 —> in binary = 5

r = 100 —> in binary = 4

Now, if we would like to have a file with read, write and executing permissions for the file owner and for the group owner of the file, but make it unavailable to all other users, we do:

chmod 770 example_file

…where example_file is any file youd like to try this command on. So, you always have to enter three separate digits, for three separate groups known already from our second lesson. The same can be done for directories.

su and sudo

It is sometimes needed for a user to become a super user, so he can accomplish a task (usually something like installing software, for example). For temporary accessing to the super user mode, theres a program called su, or substitute user. You just have to type in

su

and type your superuser password, and youre in. However, a word of warning: dont remember to log out and use it for a short period of time.

Also theres an option probably more used in openSUSE and Ubuntu, and its called sudo. Sudo is only different in the aspect, that its a special command thats allocated to one specific user. So unlike su, with sudo you can use your user password instead of the superusers password. Example:

sudo zypper in goodiegoodie

Changing file and group ownership

To change the owner of the file, you have to run chown as a superuser. For example, if Id want to change ownership from nenad to suse, I do it this way:

su

[enter password]

chown suse example_file

I can also accomplish the same with changing group ownership, but with a slightly different command chgrp. Easy peasy:

chgrp suse_group example_file

…and thats it.

Next time

As I already stated, next time well have a photo-finish of sorts. And after that, youll be on your own (along with me, wandering through the terminals darkness, with only a blinking green cursor as a lighthouse :) ). Until then geekos, remember to…

…have a lot of fun!


via: https://news.opensuse.org/2014/08/05/command-line-tuesdays-part-seven/

作者:Nenad Latinović 译者:译者ID 校对:校对者ID

本文由 LCTT 原创翻译,Linux中国 荣誉推出