1

I want ubuntu to treat my login as root. I shouldn't have to sudo. What do I do?

For almost anything I need to do, I have to sudo it. This causes problems specially in case when I need to install a software and all the directories created by it are then owned by 'root'.

I recently installed apache and /var/www was owned by root and then I had to chmod 777 to make stuff work. This is insane.

7
  • 5
    Move to superuser, no one could want to do something this insane on an actual server. Sep 7, 2009 at 4:49
  • 6
    You have /var/www CHMODed to 777? I really really really hope this isn't a production server.
    – MDMarra
    Sep 7, 2009 at 5:05
  • 2
    It might look like a troll, but it's probably just a windows user trying to move to Linux and becoming frustrated because they don't yet get the mindset needed to run a Linux server.
    – DrStalker
    Sep 7, 2009 at 5:47
  • 2
    Can someone with enough rep re-title this already? If I see UAC being compared to sudo next time I check on this thread I may stab myself in the eyes.
    – MDMarra
    Sep 7, 2009 at 7:14
  • 1
    Mindset needed huh... I'm a Windows user and I'd say most people don't have the mindset to run a server period... the platform is irrelevant ;p Sep 7, 2009 at 7:34

5 Answers 5

5

I recently installed apache and /var/www was owned by root and then I had to chmod 777 to make stuff work. This is insane.

Yeah, don't do that. Use:

chown -R www-data.www-data /var/www

Instead. Otherwise you are compromising the security of your webpages. The guides that suggest chmod things to 777 are generally writing the tutorial for shared hosting providers, because if they already have it set as 775, or 755 and chown as the www-data user there is no reason to ever chmod 777 anything unless you are sharing a file with another user on the system, but even then just cp it to /tmp

Sudo is meant to protect you from doing silly things as root that you have no business doing. If you need a temporary "root" shell, do sudo su -. Be be forwarned this should only be used a temporary. I'd suggest a TMOUT=600 in your root's .bashrc so that root is automatically kicked after 10min of idle.

I would suggest that you read Ubuntu Server Guide(direct link to pdf). Specifically chapter 8 on Security. Reading the whole book should give you great oversight on doing, maintaining and enhancing your services/quality/security.

3
  • 3
    /var/www isn't owned by www-data for a reason, the apache user shouldn't have write access to anything that it doesn't need to write. It should only need to read /var/www in almost all cases. Sep 7, 2009 at 4:43
  • Even better, just chmod -R 555 /var/www. If you need to alter config files chmod 775 temporarily to edit and then back to 555 afterwards. Sep 7, 2009 at 4:55
  • Agreed. I'll revert the chmod 777 change. Thanks for the detailed answer. Sep 7, 2009 at 7:41
3

You could set your uid to 0 in the password file.

I mean, it's a really dumb idea, but you could do it. It's the same thing as being root, but it would technically work.

3
  • This won't work, it will basically just cause you to login as root. The username doesn't matter, except when looking up the password and userid when logging in. Internally, Linux uses the UID, so once you're logged in you will be uid=0, which is root, so it's the same thing as logging in as root. Sep 7, 2009 at 7:58
  • Setting uid to 0 in passwd file caused everything to spill out 'could not find uid 1000 in passwd file' error and I couldn't log-in to ubuntu. I had to re-install ubuntu. Sep 7, 2009 at 14:22
  • wow. Sorry about that! Very interesting response, though. It must have been looking up the permissions for the files that existed in your home directory. - And @Sean - yes, he wanted root access but without logging in as root. Sep 7, 2009 at 14:46
2

In Linux, only root has all privileges. For a normal user, sudo and su are more like "Run As Administrator", not UAC. The nearest you can get is:

  • Disabling the password requirement of sudo - this is already explained in other answers (I'm not going to retype it on my phone).
  • For multiple operations, run sudo -i to get a shell running as root.
  • I'll probably be downvoted to hell for this, but there is always a way to login as root at start. (And accept all the same and even more risks than Administrator on Windows.)
1

From the way you phrase the question I assume you're coming from a windows background, and expect software to work along the same model that windows uses. Unfortunately this is not the case, and you really do need to spend some time to get your head around the new model of installation & security Linux uses.

If you seek ways to make Linux more like Windows then you'll not be happy with the results; they have very different design philosophies. To oversimplify (and risk being flamed!) the linux way is more far flexible and powerful, the windows way is less secure but easier.

1

You could grant yourself password-less sudo rights. You would still have to type sudo in front of commands that require root privileges, though. Have a look at man sudoers and also the comments in the /etc/sudoers file (which you edit with the visudo command).

Here's an interesting excerpt from my /etc/sudoers file (on Gentoo):

# Uncomment to allow people in group wheel to run all commands
# %wheel  ALL=(ALL) ALL

# Same thing without a password
# %wheel        ALL=(ALL) NOPASSWD: ALL

Your user needs to be in the wheel group for this to work.

Of course whenever it comes to permissions and security, think many times before relaxing any restrictions.

I recently installed apache and /var/www was owned by root and then I had to chmod 777 to make stuff work. This is insane.

Yep, that is insane! I highly recommend you return /var/www back to what it was.

2
  • In Ubuntu, users are usually granted sudo access by adding them to admin group (not wheel). There still is a commented-out NOPASSWD line for admins though. Sep 7, 2009 at 6:48
  • Thanks for the clarification. I thought maybe the Ubuntu /etc/sudoers might have similar commented-out config options.
    – Mike Mazur
    Sep 7, 2009 at 7:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .