0

I have already sudo-ed to an account, by running sudo su - <username> and when I try to run apt from this account I am getting the message:

[sudo] password for <username>:

which I don't have (!!!), since I was using sudo su - <username>, in order to work on behalf of account <username>, and without asking for password. Please note, that I don't have root or credentials for this server. Any help will be appreciated, since I am a bit newbie to sudo internals.

I have read this post, but it does not really shed any light and trying to read sudoers, gives me Access Denied

Edit:

It turns out that apt-get etc. cannot be located, not even by which, thus some more work needs to be done but will try to install.

Edit 2: I understand that the whole configuration, seems stupid to a lot of you, but that's what I was presented to operate with.

Yannis P.
  • 109

2 Answers2

1

When you run sudo su username or the more reasonable in most cases sudo -u username, all you are doing is starting a new shell as username. You aren't root, you're username, so in order to now run a sudo command as username, you will need username's password.

However, if what you want to do is run apt, then there's no point in logging in as username since only root can run it. All you need is to directly run sudo apt ... from your regular account and it will be the same as having run sudo apt ... as username.

terdon
  • 242,166
  • Thank you @terdon. The think is that I was given this situation as granted, hinted to use sudo su to avoid root credentials as I see, and I am trying to install a few things using sudo, right now. Thank you for your answers, it turns out I am more newbie to Linux... – Yannis P. Apr 10 '20 at 13:00
  • 1
    @YannisP. this is a personal pet peeve of mine, but don't use sudo su. Just use sudu -i or sudo -s to get a root shell. No big important reason, it's just inelegant to use two programs where one will do :). #spastikos – terdon Apr 10 '20 at 13:16
  • made a huge mistake and my distro is #RHEL thus have to use yum :(. Can't find some repos but we ll see – Yannis P. Apr 10 '20 at 18:14
-1

If your user is already added in sudoers file , then do

1) sudo su , it will ask for password , you give your user password then it will go to your root accound , from there you can run 'apt ...'

2) sudo apt ... , it will ask for your password , give your user password then it will execute the command .

  • Please don't carry on this sudo su silliness. – Chris Davies Apr 10 '20 at 13:07
  • Thank you for your answer. Have just made an edit. I didn't know to begin with, but it seems that I have to add apt-get etc. – Yannis P. Apr 10 '20 at 13:07
  • Furthermore, once you are root there is absolutely no need to use sudo again to run apt. – Chris Davies Apr 10 '20 at 13:07
  • @roaima true, I also have to install apt-get but that's fine. Btw, I was presented with this situation and I don't really like it but that's how it is. Will see what can be done – Yannis P. Apr 10 '20 at 13:09
  • @YannisP. there's no reason to install apt-get. If it isn't installed, you probably have apt and you can use that directly. Instead of sudo apt-get install, you can run sudo apt install. You might want to come into [dchat] if you have this sort of basic question. Might be easier to explain there. – terdon Apr 10 '20 at 13:17
  • @roaima : yeah but if you want to get root privilege, 'sudo su' is the only way right OR you ask admin to do the installaiton ... :) – Stalin Vignesh Kumar Apr 10 '20 at 13:30
  • @StalinVigneshKumar no! sudo su is like saying "Hello sudo, please can I have root... ok thank you. Now, hello su. Although I'm already root please can I have root? What of course? Oh, thank you". There is absolutely no need whatsoever to call su if you can use sudo. Just use sudo -s or for the more general situation sudo {command...}. – Chris Davies Apr 10 '20 at 14:11
  • @roaima : I mentioned to go to root prompt ( i meant -> root@hostname# prompt ) not to execute command , to execute command sudo { command } is fine..... – Stalin Vignesh Kumar Apr 10 '20 at 14:30
  • @StalinVigneshKumar still no! You do not need to use sudo to run root command if you are already root. – Chris Davies Apr 10 '20 at 14:32
  • @roaima Yes! because i said when you are not in root. If you are already in root , no sense in using sudo.... – Stalin Vignesh Kumar Apr 10 '20 at 14:34