6

I am aware that we can execute a command/script as a super/another user using sudo command. But Is there a possibility where the sudo utility itself is unavailable/removed by the user. If so, what could be the alternative to sudo other than su? Also, do sudo and su serve the same purpose?

2
  • I didn't downvote you, but I can see why someone might - The question could easily be interpreted as trying to get advice on hacking a system and some people might not like that. (I suspect that your question was innocent though)
    – davidgo
    Aug 9, 2013 at 8:00
  • 1
    This Question might give you some info about the different usages of su and sudo, resp. Especially Dan's answer is worth a read. (Downvote neither from me ;))
    – mpy
    Aug 9, 2013 at 8:01

4 Answers 4

7

'sudo' allows you to launch any program as any user. It is 'setuid root', as the program itself requires root permissions to do this. The power of sudo is that you can easily configure who can do what. You can allow a user to execute nmap (and only nmap) using sudo.

'su' allows you to launch a shell as any user. When you launch a shell, you can obviously launch any other program. It is therefore more dangerous; on well-administered systems, su access is generally disabled, but sudo might be available for distinct programs.

The reason why the two programs above are used is accountability. Sudo logs all requests that are made. Therefore, it is very easy for an administrator to track what a user has done using root privileges. If you grant access to a shell, a user can do whatever he/she likes (it is a 'black hole'). (Of course, advanced logging on kernel-level thwarts this).

Of course, these programs can also be marked setuid. This changes the permissions to the owner of the binary when executing it. If you manage to activate the setuid bit on e.g. /bin/bash and set the owner of /bin/bash to root, you will be root everytime you execute /bin/bash.

Lastly, physical access to the machine will allow you to do whatever you like. You can boot from a flash drive and access the local filesystem. You could even configure your bootloader to use a different init process which immediately launches a shell in single-user mode (without asking for a password).

3
  • so does that mean sudo i more preferred to su? Aug 9, 2013 at 10:03
  • It depends on the usage case - sudo is more preferred when a "normal" user needs to perform a specific task requiring enhanced access while su allows a user to behave as another user (for example root to do sysadmin maintenance on the server)
    – davidgo
    Aug 9, 2013 at 19:58
  • sudo is preferred to su for multiple reasons. First of all: you only have to enter your own password, and not remember the (complicated, or even disabled) root password. You are accountable (a log somewhere shows you did sudo), and sudo can be restricted.
    – parasietje
    Feb 29, 2016 at 8:45
14

It seems that no one has answered the question of whether or not there exist alternatives to sudo besides su, so you might be interested to know that the sudo website actually maintains a list of sudo alternatives:

http://www.sudo.ws/other.html

The list includes both open-source and commercial software. Here are the open-source sudo alternatives listed at the moment:

That said I've never used any of these alternatives, nor have I ever seen or heard of them in any other context. It also seems like at least some of these are experimental, defunct or otherwise unsupported. The impression I get is that sudo and su are the only real game in town.

2

Log in as root (if allowed on your tty) or reboot the computer and log in with init=/bin/bash on the command line to restore the required functionality.

I point out that only root can remove sudo.

sudo and su serve similar but different purposes. "sudo" allows you to do something with someone elses permissions while "su" allows you to "become" that user and lets you behave like them.

1

If the machine has openssh-server installed, then an alternative to sudo might be:

ssh root@localhost ..command.. ..goes.. ..here..

If it hasn't been disabled then there is su as you mentioned:

su - root -c "..command.. ..goes.. ..here.."
0

You must log in to answer this question.

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