2

Suppose, I have just entered the Metasploitable 2 Linux like the following command:

username : msfadmin
password : msfadmin

Now, I need to gain 'root' privilege so that I do not need to use 'sudo' - command again and again. For example, in order to shutdown the machine I just want to type:

shutdown -h 1

not,

sudo shutdown -h 1

How to do that?

2 Answers2

3

On UNIX like system root rights are defined by the user id (which is 0 for the root user). I will offer two preferable options first.

1. Switching to root user

If you want to become the root user for the current session only a

$ sudo su

should be sufficient.

2. Disabling sudo password check

You can edit the sudoers file using

$ sudo visudo

, append the following line and save the file.

msfadmin ALL=(ALL) NOPASSWD: ALL

Note: if the visudo command uses an unwanted editor you can use (replacing nano by the editor you want to use):

$ EDITOR=nano sudo visudo

3. Setting user id to 0

I would really not recommend this way but to make msfadmin a root user change its user id to 0.

$ sudo nano /etc/passwd

, change the line starting with msfadmin to msfadmin:x:0:0:msfadmin,,,:/home/msfadmin:/bin/bash and reboot.

jnodorp
  • 1,476
  • 12
  • 14
0

On metasploitable-2.6.24-16-server:

When you restart the machine press Esc and boot in the recovery mode. You will see a blue menu. Choose option 2 root : drop to root shell prompt. Change the password by typing passwd root, restart the machine in the normal mode and login with the root privileges.

Stephen Kitt
  • 411,918
  • 54
  • 1,065
  • 1,164
Osama_978
  • 11
  • 1
  • @Peregrino69 actually, the OP is asking how to get root privileges. The `shutdown` command was just an example: *"Now, I need to gain 'root' privilege so that I do not need to use 'sudo' [. . .] For example, in order to shutdown..."*. Also see [their comment](https://unix.stackexchange.com/questions/194825/how-to-achieve-root-privilege-in-metasploitable-2-linux/671439#comment326762_194847). – terdon Oct 03 '21 at 09:09
  • @terdon Right you are, I misunderstood the question. Gotta do a bit of editing here... – Peregrino69 Oct 03 '21 at 09:12
  • @Peregrino69 no worries. Been there, done that! – terdon Oct 03 '21 at 09:13
  • @Osama978 Welcome (again) to Unix&Linux :-) I re-formatted your question a bit to better fit Q&A site, the edit will become visible when (if) a senior community member approves it. Check back later today or tomorrow to verify I didn't change the meaning. Please note, SE sites aren't discussion forums but Q&A sites, a different concept as described in the Tour. I'd also recommend checking the Help section to learn how to answer and ask, among other things. It's advisable to check those in every new community you join as the details differ depending on the focus area of the community. – Peregrino69 Oct 03 '21 at 09:18