Daily Tip 2015-10-25

Source: Internet
Author: User

To summarize the knowledge of the SU and sudo commands and related environment variables today

Sudo is a way for ordinary users to have administrator privileges, unlike direct su, which requires the user to be in the sudo group
Using the sudo command, the equivalent of root has been granted.
If there is anything you want to know about this, you can look at the man or go to search engines to find out.
The important thing that I forget is that either the SU or the sudo command. Must have been added a"-", which is in the English state of the quotation marks.Hyphen Character、
Adding that can change the environment variables. As for what is the environment variable, I'll go on to say it later.

First of all, the sudo configuration, if the hand lazy can be directly visudo, but in fact, his configuration file in/etc/sudoers
[Email protected]:~#Visudo
Visudo:/etc/sudoers.tmp not changed
[Email protected]:~#vi/etc/sudoers
Sudoers sudoers.d/
[Email protected]:~# vi/etc/sudoers

In fact, vi open the whole road by a more reliable point
Then is to enter the VI command mode, the direct input/root search the root of the row, press N for the next jump.
Find this line.
# User Privilege Specification
root all= (all:all) all

# Allow members of the group sudo to execute any command
%sudo all= (all:all) all

According to its format in the root of the line after the press I edit plus an ordinary user, if you do not want to give it only a few permissions, my advice is directly in addition to root to give it the same.
Recommended direct copy and paste ha, in fact, it above the line has given you a hint, for example, just want to give it a halt command, write on the entire path is placed in the third segment, multiple commands separated by commas.
Which of the following% starts with a user group, and if you want to add a user group, add it below it.
Then save and exit.

In the terminal input sudo-l can see the current user has permissions

[Email protected]:~#sudo-l
User root can run the following command on LP:
(All:all) All
[Email protected]:~#

Now let's talk about that environment variable.
Enter the Echo $PATH at the command line to view the current user's environment variables.
[Email protected]:~#Echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

There are two problems when you enter a command prompt command in the terminal: the first is that the command does not exist, and the environment variable is not.
For example, create a new script. I went straight to the command line, huh?
[Email protected]:/tmp# ls
[Email protected]:/tmp# VI ll.sh
[Email protected]:/tmp#
[email protected]:/tmp# cat ll.sh L
echo "This is a test"
Cat:l: No file or directory
[Email protected]:/tmp# cat ll.sh
echo "This is a test"
[Email protected]:/tmp# chmod u+x ll.sh
[Email protected]:/tmp# ll
Total Dosage 4
-rwxr--r--1 root root 22 October 13:43 ll.sh
[Email protected]:/tmp#
[Email protected]:/tmp# ll.sh
bash:ll.sh: Command not found
[Email protected]:/tmp# pwd
/tmp
[Email protected]:/tmp# Echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
################################
#下一行就是一个临时修改环境变量 #
################################
[Email protected]:/tmp#path= "$PATH:/tmp"
[Email protected]:/tmp#
[Email protected]:/tmp#
[Email protected]:/tmp# Echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/tmp
[Email protected]:/tmp# ll.sh
This is a test
[Email protected]:/tmp#
[Email protected]:/tmp#
[Email protected]:/tmp#

However, the above practice, after restarting or logoff environment variables will be invalidated, then how to let him be effective all the time?
There are two ways, one is to throw in the boot from the file, each boot will let him take effect, another way is to modify the configuration file
The location of the configuration file is/etc/profile

[Email protected]:/tmp# head/etc/profile
#/etc/profile:system-wide. profile file for the Bourne shell (SH (1))
# and Bourne compatible shells (Bash (1), Ksh (1), Ash (1), ...).

if ["' id-u '"-eq 0]; Then
Path= "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
Else
Path= "/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games"
Fi
ExportPATH

I guess these files are not the same on your system, I'm using that kali2.0, it's a single-user system,
If it is root login, the result of Id-u is 0, then the environment variable is the above, if it is a normal user, the environment variable is the following one.
You can also add the following directly
path= "/tmp: $PATH"
This is also possible, as long as you want to add the path with a colon separated by adding it can be.
If you want it to take effect immediately.
PerformSource/etc/profile
If you just want to modify an environment variable for a normal user, you can find it in the user's home directory.~/.BASHRCor ~/.bash_profileMake changes
Well, that's summed up so much, after all, hand-beating, so it is.

This article comes from the "Dashazi's blog" blog, please be sure to keep this source http://dashazi.blog.51cto.com/10354524/1706018

Daily Tip 2015-10-25

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.