0

I am running Centos 8.

I have used various instructional documents, such as the below:

https://www.cyberciti.biz/faq/how-to-sudo-without-password-on-centos-linux/

in an attempt to be able to ssh to an account, and then get to root without having to use a password. I am accessing my machine via passwordless ssh with a key that requires a passphrase.

Once I have logged in, with my account, I want to be able to sudo to root without a password.

Is that even possible?

What I have done is logged in as root (Which DOES require my account password) and then:

visudo

And added this line here for the account for "Keith".

keithchegwin ALL=(ALL) NOPASSWD:ALL

Now, for "good measure" I have started sshd again, and logged back in as keithchegwin fully expecting to be able to do:

su root

With no password, but it still asks for a password for the account I am logged in as. I want it to stop!

What am I doing wrong? Thanks.

I did see his other question here, but that refers to running a specific script or program, not accessing an account with no password so I do not think this is a duplicate:

How to run a specific program as root without a password prompt?

0

2 Answers 2

1

sudo and su are two different commands, and do different things.

su on its own won't do passwordless.

With your setup, you could do something like sudo su and it won't ask for a password. Or, more simply sudo -i or sudo -s.

2
  • sudo -i is recommemded. WIth sudo -s you may not get the extra system path for root.
    – GMaster
    Feb 17, 2022 at 3:14
  • Tried it, thanks, it still asks for the password of the user I have accessed the server as...
    – Scouse_Bob
    Feb 17, 2022 at 3:42
0

You can try sudo su root. Also, you only want to enter root privileged shell, the next command is worked too: sudo -s. Difference between both, sudo su root inherits all currently environment variables, sudo -s equals sudo "$SHELL". For example, in sudo -s, if your default shell is /usr/bin/zsh, you'll be the same as sudo "/usr/bin/zsh".

1
  • Use sudo -i instead of the clunky sudo su root Jan 8 at 16:21

You must log in to answer this question.

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