0

Currently I am running a server on vnc with RHEL 7 operating system.

Background:

  1. I login to the server say kpod@server1
  2. Now when I need to access root permissions. I use the path /tools/xgs/bin/sudo su -
  3. Instead of the full path, how can I get root access with only running command sudo?

Note:

  • /etc/ contains - sudoers.rpmsave
  • /etc/ doesn't contain sudoers.d

How can I become root with running only sudo?

Edit: /tools/xgs/bin/sudo is the path where the sudopackage is stored.

Kamalikap
  • 13
  • 5
  • 1
    Is server1 really RHEL or is it Solaris? – Chris Davies May 20 '20 at 23:20
  • Do you need a sudo binary in the existing path? Or is this just about the user you log in as? You could define an alias in the user's shell config or change PATH for that user. – Hauke Laging May 20 '20 at 23:27
  • You could also use sudo -s (or sudo -i, I suppose) instead of this horrible sudo su malarky – Chris Davies May 20 '20 at 23:31
  • @roaima- When I do "cat /etc/os-release"- I get the below output:

    NAME="Red Hat Enterprise Linux Workstation" VERSION="7.4 (Maipo)" ID="rhel" ID_LIKE="fedora" VARIANT="Workstation" VARIANT_ID="workstation" VERSION_ID="7.4" PRETTY_NAME="Red Hat Enterprise Linux Workstation 7.4 (Maipo)"

    – Kamalikap May 21 '20 at 01:31
  • @roaima- "sudo " is present in the path /tools/xgs/bin/sudo.

    sudo : command not found if I try "sudo -s".

    – Kamalikap May 21 '20 at 01:36
  • @HaukeLaging - It is for all users. I tried using alias for user shell but the sudo command is not recognized by the shell. – Kamalikap May 21 '20 at 01:59
  • 1
    What is there to be recognized? If you do alias sudo=/tools/xgs/bin/sudo and then sudo -s that "has to work". – Hauke Laging May 21 '20 at 02:03
  • @HaukeLaging- Doesn't works.
    1. edited the .user.sh file
    2. alias sudo=/tools/xgs/bin/sudo
    3. trying to login:

    #sudo -s bash: sudo: command not found...

    – Kamalikap May 21 '20 at 04:40
  • 1
    @K-pod Add that alias to your ~/.bashrc file. Log out, then log in, then use sudo. – Kusalananda May 21 '20 at 06:31
  • You can execute alias sudo=/tools/xgs/bin/sudo in the running shell. No need for putting it in a config file in the first step. Usually you want to know whether it works before you put it in a config file. – Hauke Laging May 21 '20 at 19:49
  • Thanks @Kusalananda. It works! – Kamalikap May 21 '20 at 21:16

1 Answers1

0

There are two solutions to this sort of thing:

  1. Add a simple alias to your ~/.bashrc file (or wherever you usually define aliases):

    alias sudo=/tools/xgs/bin/sudo
    

    Then log out and log in again (or at least open a new terminal). The alias should then be active.

  2. Modify your PATH variable (possibly also in ~/.bashrc) by appending the path where the sudo command lives:

    PATH=$PATH:/tools/xgs/bin
    

    This would additionally give you access to all other executables at that path. The same thing applies here, log out and in again, or at least open a new terminal.

For testing either of these variations before you add them to your shell's startup file, you could just give either of the above commands in an interactive shell.

Also note that sudo su is never really necessary. See e.g. "Is there ever a good reason to run sudo su?"

Kusalananda
  • 333,661