In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "what are the functions of the sudo command of linux". In the daily operation, I believe that many people have doubts about the functions of the sudo command of linux. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "what are the functions of the sudo command of linux?" Next, please follow the editor to study!
The sudo command is convenient when you want to run a command temporarily with super privileges, but you can have some trouble when it doesn't work as you expect. For example, if you want to add some important information at the end of some log files, you might try to do this:
$echo "Important note" > > / var/log/somelog-bash: / var/log/somelog: Permission denied
Well, it looks like you need some extra privileges. In general, you cannot use your user account to write to the system log. Let's try again with sudo.
$sudo! sudo echo "Important note" > > / var/log/somelog-bash: / var/log/somelog: Permission denied
Well, it's still not responding. Let's try something different.
$sudo 'echo "Important note" > > / var/log/somelog'sudo: echo "Important note" > > / var/log/somelog: command not found
What's next?
The above response after the first command shows that we lack the necessary privileges to write to the log file. The second time, we ran the first command with root privileges, but returned a "no permission" error. The third time, we ran the entire command in quotation marks and returned a "command not found" error. So, what's wrong with it?
The first command: you cannot write to this log without root privileges.
The second command: your super permissions do not extend to redirection.
The third command: sudo does not understand the entire "command" enclosed in quotation marks.
And if your users have not yet been added to the sudo user group, if you try to use sudo, you may have seen an error like the following:
Nemo is not in the sudoers file. This incident will be reported.
What can you do?
A fairly simple option is to use the sudo command to temporarily become root. Given that you already have sudo privileges, you can do this using the following command:
$sudo su [sudo] password for nemo:#
Note that the prompt for this change indicates your new identity. Then you can run the previous command as root:
# echo "Important note" > > / var/log/somelog
Then you can enter ^ d to return to your previous identity. Of course, some sudo configurations may prevent you from using the sudo command to become root.
Another way to switch users to root is to use only the su command, but this requires you to know the root password. Many people are given access to sudo without knowing the root password, so this is not always feasible.
After switching to root (using su directly), you can run any command you want as root. The problem with this approach is: 1) everyone who wants to use the root privilege needs to know the root password in advance (which is not very secure); 2) if you fail to exit the privileged state after running a specific command that requires root permission, your system may be affected by some major errors. The sudo command is designed to allow you to use root permissions only when you really need them, and to control the root permissions that each sudo user should have. It also makes it easy for you to return to the normal user state after using the root privilege.
Also note that the premise of the whole discussion is that you can access sudo normally and that your access is not restricted. The details will be covered later.
Another option is to use a different command. If it is an option to add content later by editing the file, you may want to use sudo vi / var/log/somelog, although editing an active log file is usually not a good idea, as the system may write to it frequently.
The last but somewhat complex option is to use one of the following commands to solve the problems we've seen before, but they involve a lot of complex syntax. The first command allows you to use it after you get a "no permission" refusal! Repeat your orders:
$sudo echo "Important note" > > / var/log/somelog-bash: / var/log/somelog: Permission denied$!: gs/ > / | sudo tee-a /
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.