Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question
    
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 '13 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 '13 at 8:01
add comment

4 Answers 4

up vote 3 down vote accepted

'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).

share|improve this answer
    
so does that mean sudo i more preferred to su? –  AlwaysALearner Aug 9 '13 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 '13 at 19:58
add comment

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.

share|improve this answer
add comment

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.."
share|improve this answer
add comment

If sudo isn't installed (or you aren't allowed by it's configuration to use it), and you don't have access to root's password for su, it is the policy of the administration of the machine. Take it up with them, I will not help anybody go against the machine's management.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.