How to gain root ac...
 

How to gain root access in Linux (experts only)  

Page 1 / 3
  RSS

Hunter O'Gold
(@hunterogold)
Eminent Member
Joined: 2 months ago
Posts: 23
2020-02-21 7:06 am  

[This may be in the wrong section or might need a section of its own for Linux users]

Many times, when configuring Linux from the command line, which is very common in robots, using sudo for every command can become tiresome. It is for me.

I must stress here that having root access to your Linux operating system is a responsibility and is extremely dangerous. You could easily render your operating system unusable. I have broken hundreds of them even with three decades of experience.

So, here are some important rules to learn, and always abide by, if you intend to try this:

  1. Only stay logged in to root for as long as absolutely necessary. You can log out using Ctrl-D or with the exit command.
  2. Never log directly into the console using the root account. Only ever log in to the root account using the su command from another account and always log out immediately after you have done what you needed to do.
  3. Always use a strong password for the root account. If you lose access to the root account, the person who gains control literally becomes God and you have effectively lost control of your system.

If that hasn't scared you off, and for most of you it should have, this is how you become root.

  1. Open a terminal. Any terminal will do, this isn't hard.
  2. Type in:
    sudo bash
  3. And hit enter. You will be asked for a password. Enter your personal password and hit enter.
  4. If you do actually have sudo access to the system (hackers be gone), you will now become root.
  5. Type in:
    passwd
  6. Followed by enter. Now type in the very very strong root password you have chosen for root (as you type nothing will appear).
  7. Hit enter and type it in again. Hit enter again.
  8. Now hit Ctrl-D or enter the exit command.
  9. You should now be back in your own account.

You now have root access. To gain access simply use the su command with your very very strong password. You will not need to use sudo while you are logged in as root. And always log out immediately after you have finished what you needed to do. Use Ctrl-D or exit to do this.

I hope this was helpful and please be very very careful. With vast power comes vast responsibility.

This topic was modified 1 month ago 5 times by Hunter O'Gold

The simplest solution is probably correct.


Quote
Topic Tags
Robo Pi
(@robo-pi)
Robotics Engineer Moderator
Joined: 10 months ago
Posts: 1590
2020-02-21 9:34 am  

I have a related question for you.

I'm running Ubuntu 18.04 (Bionic Beaver) on Jetson Nanos.   I already have it set up to ignore passwords.  I already use the su command.   I'm not worried about anyone taking over these systems as I back up their system SD cards regularly and could revert back to them should I ever lose control.  I also don't keep information on these computers that I wouldn't want the public to see.   So there's basically no security risk to these machines.   Plus I'm the only person who ever uses them physically.  The only intruders would have to be hackers on the Internet.

Having said all of the above, these systems do actually have a password.  I simply have them set up so that I don't ever need to actually enter it.   They don't ask for a password when booted up and while they do require sudo (unless your using the su command) they don't ask for a password ever.  Which is fine with me.

However, there is one exception!   When I use the software install program from the desktop, it does ask for my password.  And I haven't been able to figure out how to stop it from asking.  It doesn't ask for my password when I install a program from the command line.   It only asks for a password then I use the desktop shopping bag program installer.

So do you have any ideas why it's asking me for a password there?  And how I might get it to stop asking for a password?

For these specific computers I'd be just as happy if they didn't have any passwords at all.   Like I say there's no information on them that is secret.  And I have backup system  SD cards should I ever lose control of them.

Sometimes there's just no need for security on a computer system.  These little nanos I have set up are a situation where passwords are just a pain.   I just don't need them.   Although, the system does have a password underneath it all.  As you can see here, it's still asking me for the password when I use the shopping bag program installer on the desktop.  And I haven't figured out how to get around that one yet.

Any ideas?

DroneBot Workshop Robotics Engineer
James


ReplyQuote
frogandtoad
(@frogandtoad)
Reputable Member
Joined: 9 months ago
Posts: 384
2020-02-22 6:38 am  

@hunterogold

Posted by: @hunterogold

If that hasn't scared you off, and for most of you it should have, this is how you become root.

  1. Open a terminal. Any terminal will do, this isn't hard.
  2. Type in:
    sudo bash
  3. And hit enter. You will be asked for a password. Enter your personal password and hit enter.
  4. If you do actually have sudo access to the system (hackers be gone), you will now become root.
  5. Type in:
    passwd
  6. Followed by enter. Now type in the very very strong root password you have chosen for root (as you type nothing will appear).
  7. Hit enter and type it in again. Hit enter again.
  8. Now hit Ctrl-D or enter the exit command.
  9. You should now be back in your own account.

You now have root access.

Indeed, this is true, but as you already noted, you actually do need to be part of the sudo group to be able to do that in the first place.  Having said that, as the default shell is usually bash, so you should just be able to type: "sudo passwd root <enter>" and follow the prompts from there.

Whilst this is generally OK for a developer on their personal system, it's not OK to even attempt it when working for a company... you can be caught out and sacked, even for just attempting it for curiosity!

Personally, I don't see it as a problem... how many times do you have to enter it anyway?


ReplyQuote
Hunter O'Gold
(@hunterogold)
Eminent Member
Joined: 2 months ago
Posts: 23
2020-02-22 6:44 am  

You could do that but this method is more instructive and using sudo defeats the purpose of the lesson. I do agree that unless you are a system administrator or need this ability for experimentation, sudo is a serviceable method.

The simplest solution is probably correct.


ReplyQuote
frogandtoad
(@frogandtoad)
Reputable Member
Joined: 9 months ago
Posts: 384
2020-02-22 6:46 am  

@robo-pi

Posted by: @robo-pi

However, there is one exception!   When I use the software install program from the desktop, it does ask for my password.  And I haven't been able to figure out how to stop it from asking.  It doesn't ask for my password when I install a program from the command line.   It only asks for a password then I use the desktop shopping bag program installer.

So do you have any ideas why it's asking me for a password there?  And how I might get it to stop asking for a password?

Since it is your own system, you should check and compare the groups assigned to root vs your own account.  But you haven't told us under which user you use the command line... su as root? or sudo?

Just type in groups <enter> to see what groups you are a member of... I'm betting you're not in the "root" group, which is "groups root <enter>" right? 🙂

Cheers!

This post was modified 1 month ago by frogandtoad

ReplyQuote
frogandtoad
(@frogandtoad)
Reputable Member
Joined: 9 months ago
Posts: 384
2020-02-22 6:52 am  

@hunterogold

Posted by: @hunterogold

I do agree that unless you are a system administrator or need this ability for experimentation, sudo is a serviceable method.

Yes, that was my point, but raising this was a valuable lesson for when and how to use it!

Cheers!


ReplyQuote
Robo Pi
(@robo-pi)
Robotics Engineer Moderator
Joined: 10 months ago
Posts: 1590
2020-02-22 7:06 am  
Posted by: @frogandtoad

Just type in groups <enter> to see what groups you are a member of... I'm betting you're not in the "root" group, which is "groups root <enter>" right?

Yep, you're right I'm not a member of root.  How do I become a member of root?

I'm about as far from being an expert on Linux as a person can be. ? 

The thing I really hate is when I own a computer that I can't even gain total control over. ? 

I should be able to tell my computer to do anything I want, including to quit pestering me with passwords. ? 

DroneBot Workshop Robotics Engineer
James


ReplyQuote
Hunter O'Gold
(@hunterogold)
Eminent Member
Joined: 2 months ago
Posts: 23
2020-02-22 7:09 am  

@frogandtoad

I thought it was implied that (on most personal Linux systems) you would be logged in on your account. On public systems, you would be unlikely to have sudo privileges.

For example, on Rasperian, you would be logged in as pi. Pi has sudo privileges allowing you to elevate your privileges to root. I assumed that most Raspberry Pi robotics hobbyists would chose to use Raspberian. 

Myself, I use a cut-down version of Ubuntu.

The simplest solution is probably correct.


ReplyQuote
frogandtoad
(@frogandtoad)
Reputable Member
Joined: 9 months ago
Posts: 384
2020-02-22 7:10 am  

@robo-pi

You can add yourself to the root group via the GUI, or command line, as long as you can obtain root privileges to make such a change in the first place 🙂

You can also look up: "chown" change ownership.

Cheers!


ReplyQuote
frogandtoad
(@frogandtoad)
Reputable Member
Joined: 9 months ago
Posts: 384
2020-02-22 7:17 am  

@hunterogold

Posted by: @hunterogold

I thought it was implied that (on most personal Linux systems) you would be logged in on your account. On public systems, you would be unlikely to have sudo privileges.

I'm not actually sure what you mean by this, because on personal systems, you are logged into your account, which if you as the user installed it in the first place, will most likely be added to the sudo group by default.

Again, not sure what you determine to be a public system?  If you mean a system as part of your employment/job/role... indeed, you will most likely NOT be provided with such privileges... unless you know the Administrator 😉

Cheers!


ReplyQuote
Hunter O'Gold
(@hunterogold)
Eminent Member
Joined: 2 months ago
Posts: 23
2020-02-22 7:19 am  

@frogandtoad

That is what I meant by that 😀

The simplest solution is probably correct.


ReplyQuote
frogandtoad
(@frogandtoad)
Reputable Member
Joined: 9 months ago
Posts: 384
2020-02-22 7:21 am  

@hunterogold

LOL... no problemo 😉


ReplyQuote
codecage
(@codecage)
Member Admin
Joined: 10 months ago
Posts: 507
2020-02-22 7:47 pm  

@robo-pi

How about being a member of "sudo"?

I think that just asks for the password the first time you use 'sudo' during a logged in session.

That's probably a better group to be in than "root"

SteveG


ReplyQuote
VE1DX
(@ve1dx)
Estimable Member
Joined: 8 months ago
Posts: 122
2020-02-22 8:11 pm  

@robo-pi

As @hunterogold described, all you have to do with Raspbian to enable the root account is, from the pi account, is to type:

sudo passwd root

You'll then be prompted to enter a password (twice) and this enables the root account.  To use it from pi (or any other account on your Raspbian system, type:

su - root

It'll prompt you for the root password, and then you are logged on as root.  As everyone says, this allows you to do anything, and it's easy to mistakenly destroy your system with the wrong command(s.)  However, often it's useful to have true rood access if only to avoid having to type sudo in front of commands that require administrator permissions.

pi@drone:~ $ su - root
Password:

Wi-Fi is currently blocked by rfkill.
Use raspi-config to set the country before use.

root@drone:~# ls -la
total 36
drwx------ 6 root root 4096 Feb 19 13:24 .
drwxr-xr-x 21 root root 4096 Feb 13 12:31 ..
-rw------- 1 root root 59 Feb 21 16:27 .bash_history
-rw-r--r-- 1 root root 570 Feb 8 22:47 .bashrc
drwx------ 2 root root 4096 Feb 13 12:31 .cache
drwx------ 3 root root 4096 Feb 19 13:23 .config
drwxr-xr-x 3 root root 4096 Feb 19 12:51 .local
-rw-r--r-- 1 root root 148 Feb 8 22:47 .profile
drwx------ 3 root root 4096 Feb 13 12:31 .vnc
root@drone:~# logout  <--- (or ctrl + d)
pi@drone:~ $

Note the prompt for root is # instead of $, although it does give the root name in the prompt line, so it's hard to know your not logged on as root.  Once you su (switch user) to root, it won't prompt you for passwords or say "are you sure?" so be careful.  I have destroyed several systems by deleting critical files only to say "Oops!" as soon as I hit return.

Paul VE1DX

Nova Scotia weather: https://www.ve1dx.net/


ReplyQuote
Pugwash
(@pugwash)
Prominent Member
Joined: 10 months ago
Posts: 969
2020-02-22 8:12 pm  
Posted by: @codecage

@robo-pi

How about being a member of "sudo"?

I think that just asks for the password the first time you use 'sudo' during a logged in session.

That's probably a better group to be in than "root"

There is no fundamental difference between root and SuperUser (SU). Root privileges are also assigned to underlying activities used by the OS in the background, this can be anything from network admin task to file handling tasks (NOT TO BE MESSED ABOUT WITH LIGHTLY). Most of these activities can be seen on a macOS with the Activity Monitor, I believe Linux has something similar, not sure about Windows. Logging in as the SuperUser gives you all the privileges that you need.

@robo-pi, as the SU, you have all the omnipotence of an OS dictator that you need for your Rasberry Pi Banana Republic.

SteveC - Topple Rudd Poltman


ReplyQuote
Page 1 / 3

Please Login or Register