قالب وردپرس درنا توس
Home / Mac / At the beginning there was Sudo: MacOS Terminal Skills

At the beginning there was Sudo: MacOS Terminal Skills



After putting on our last 4-day JAMF200 course, it was great to watch some command line friends from earlier times. Time to encounter these makOS Terminal skills.

Include Sudo (and Disclaimer Of Course)

Enter the following "Whoami" command (exclude Amsys $ bit) in a MacOS Terminal window and you get Current User:

  Amsys $ whoami
barring n 

Run the same command with & # 39; sudo & # 39; and the end of & # 39; whoami & # 39; now shows the & # 39; root & # 39; the user instead of & # 39; barring no. Nice!

  Amsys $ sudo whoami
root 

OK, why is this useful? The Sudo (Superuser) command is definitely one of the most powerful unix commands, and those who regularly spend time on CLI quickly learn their applications. It allows the user to temporarily get superuser privileges with default that usually be root (aka system administrator account) and thus provide the ability to perform system administration maintainer etc. Time to read this disclaimer below.

"Sounds pretty cool! Tell me more, please!"

OK. In another example, let's say you want to check if remote login is enabled on the computer you are on. We can check this in GUI (via System Preferences), but as we all are about CLI today, let's see how easy this is. Runs the following command (again, after Amsys $) without superuser privileges, you get this:

  Amsys $ systemetup -genremotelogin
You need administrator access to run this tool ... exciting! 

Repeat the sudo command initially, authentically, and discard:

  Amsys $ sudo systemsetup -genremotelogin
Password:
Remote login: On 

Sudo …… the common misconception

One of the common mistakes of this super cool superuser unix command that I've heard a lot recently on our Support Essentials course is that it is only used to provide root-level access to a standard user. Or just to bypass any "permission denied" issues that can be presented with.

While true, it's actually much more powerful because it can run commands like any user, not just the root user.

Use example at the beginning of this post if we now perform the same & # 39; whoami & # 39; command with & # 39; sudo -u username, we get the following:

  sudo -u bob whoami
bob 

Again, production confirms that we now act as "bob".

Being able to run commands as any user is definitely a useful tool for having in the box. In addition, there is a similar command called & # 39; su & # 39; for & # 39; switch user & # 39 ;. We park it for a future blog post.

More Sudo Nuggets

  1. Of course, you will be prompted for your password when you run a sudo command for the first time. However, run another sudo command within 5 minutes and you will not. This is because your credentials are cached (only in the current screen) for 300 seconds, so you do not need to continue authentication. Create a new Terminal window and you will be prompted again though.
  2. As with most things in macOS, it's a log file for it! This includes sudo. Use the Console app (find MacOS Spotlight via CMD + Space). Within console search for process: sudo:
  3. And …… for when you forget to write sudo:

Enter a command (even if it's short in length) and then you realize you've forgotten Adding the sudo command at the beginning is simply annoying. You can of course, the up arrow to call the last written command and then add sudo to the beginning, or worse, print it again. This trick ignores the need:

  sudo !! 

Using this simple command, runs the previous type of command using sudo. Nice!

So there we go, hopefully it gives a little more background to using sudo. For more information on the command line, check out our Command Line Essentials course.
All Important Disclaimer:
Obviously comes with great power at great risk and therefore it is best to leave system administrators to this in your life / production environment. Just give users the access they need to perform their roles in a test environment, it's quite fun, breaking things in a living environment is not!

83094972240610 & # 39;); fbq (& # 39; Tracks & # 39 ;, PageView & # 39;);


Source link