How do I shut down my Linux VM from the command line and manage sudo privileges?

0
17
Asked By SillyGoose42 On

I just set up Linux as a Hyper-V VM on Windows 11 using the "debian-12.11.0-amd64-DVD-1.iso". I can connect via SSH with Termius and transfer files, but I'm trying to find out how to shut down the Linux VM using the command line. I keep getting a 'command not found' error when I type `shutdown`. Is `shutdown` the right command to use? Also, I noticed that a lot of commands need 'sudo'. I tried that, but it says my user 'lowpriv' isn't in the sudoers file, so I think I need to add it to that group. Is the 'sudoers' group similar to the Administrators group in Windows? Do I need root access to edit that file? I remember setting a password for the root user during installation, which I assume is like the Administrator account in Windows.

4 Answers

Answered By KnowItAllKid On

You don't have to log in as root to edit the `sudoers` file. If you can gain root access temporarily through other means (like a root password you set), you can edit it safely. No need to mess with root all the time, just add your user to the `sudo` group for tasks that need administrative access.

Answered By TechieTommy On

The issue with the `shutdown` command is that it's located in `/sbin`, which isn't in the standard path for non-root users. To shut down the system, you could use the command `/sbin/shutdown`. However, as a non-root user over SSH, you'll typically need the privileges to do this, which means you might not be able to shut down without being part of the `sudo` group. You'll need to add your user 'lowpriv' to that group to use `sudo`. You can usually do this with the `adduser lowpriv sudo` command, but you need root access to run it.

Answered By LinuxLover123 On

Yes, `shutdown` is correct. Though you might also want to try `halt` as that can work too. Regarding the `sudoers` group, it's similar to the Administrators group in Windows, but remember, simply adding your account to the `sudo` group allows you to use `sudo`. You don't need to log in as root all the time; just make sure your account is in that group and then you can use commands like `sudo shutdown` without any hassle. It's generally safer to disable the root account and rely on `sudo`.

Answered By HelpfulHal On

To manage the shutdown, once you have `sudo` working, the command you'll need to use is `sudo shutdown now`. This will shut down your system right away. Just a heads up, make sure you have physical access to your VM’s host if needed, since remote shutdowns can be tricky.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.