-1

On my centos 7 vps server, to secure my server I disabled root login via ssh. I created a new user called erdem and login with that user via ssh. After I login via ssh with user erdem, I would like to switch to root user with su command or su -s command. When I do that I get this error:

-bash: /usr/bin/su: Permission denied

How can I give permission to user called erdem so I can switch with su or su -s command to root.

The output of ls -l /usr/bin/su:

 -rwsr-x--- 1 root wheel /usr/bin/su

I tried to add the user into wheel group but it still gives the same error.

I used bellow command

gpasswd -a erdem wheel

Solved: I needed to logout and login again.

marked as duplicate by ctrl-alt-delor, Kusalananda Apr 12 at 21:27

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Error apart, what you want to obtain is more commonly done via sudo -s. Doesn’t it work for you ? – LL3 Apr 12 at 16:06
  • su is also a valid means to become root, particularly if sudo is not yet installed, or the newly-created non-root user is not yet in sudoers. OP, can you please add the output of the following to your question: ls -l /usr/bin/su – DopeGhoti Apr 12 at 16:13
  • when I do that it asks for a password for the user and when I type it I get this message erdem is not in the sudoers file. This incident will be reported. – Erdem Ece Apr 12 at 16:13
  • su expects the target user's password (root in this case). sudo expects the password of the user executing the command (yours). su on some systems can only be executed by users in particular groups (wheel on BSD, for example), but I'm unsure how this works on CentOS. – Kusalananda Apr 12 at 16:14
  • 1
    Please add details by editing the question, not by adding them to the comments. – DopeGhoti Apr 12 at 16:24
-1

The permissions for su look abnormal to me. Here are the permissions I see on another CentOS machine:

-rwsr-xr-x. 1 root root 32208 Mar 14 10:37 /usr/bin/su

Note that your copy of su does not have the execute permission for users not in the wheel group, who are not already the root user.

On your system, no one will be able to su even knowing the root password if they are not in the wheel group.

  • after adding the user wheel group I didn't know I needed to logout and login again. Thanks. – Erdem Ece Apr 12 at 16:31
  • This is the traditional way. The purpose of group wheel is to be able to use su to change to root. I think the check was originally in the command, as doing it this way prevents users switching to another non-root user (with password). – ctrl-alt-delor Apr 12 at 16:36

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