Author Topic: sudo within ssh remote  (Read 1625 times)

0 Members and 1 Guest are viewing this topic.

Offline John231

  • Jr. Member
  • **
  • Posts: 1
  • Karma: 0
  • I've just joined!
    • View Profile
    • Awards
sudo within ssh remote
« on: July 23, 2018, 07:06:33 am »

If somebody can help me plese. I am a complete newbie :(

I have 2 servers.....

I have no access to root, nor to sudoers file in any server.

I have a server that is named server1 (the server). And i have another server2 (the client)

In server1 i log in with user operador (it's the only password i have), and i have permission to do:

(root) NOPASSWD: /bin/su - sauron

So i do : sudo su - sauron , and then when i do: sudo -l , i get:

User sauron may run the following commands on this host:
(root) NOPASSWD: /etc/init.d/tomcat
(root) NOPASSWD: /etc/init.d/romillot

So i do : sudo /etc/init.d/romillot [stop/start/status]

In server2 i have only the password for operador.

I have configured the remote ssh without passwrod, so i am able to do :

[email protected]:~/.ssh$ ssh [email protected] "uname -a"
Linux server1 2.6.39-300.17.2.el6uek.x86_64 #1 SMP Wed Nov 7 17:48:36 PST 2012 x86_64 x86_64 x86_64 GNU/Linux
[email protected]:~/.ssh$

And now I am trying to remotely restart the romillot service (using the ssh without password). So I try to do something like:

ssh [email protected] "sudo su - sauron /etc/init.d/romillot status"

But at first i get:
sudo: sorry, you must have a tty to run sudo

I try other things:

[email protected]:~/.ssh$ ssh [email protected] "/bin/bash sudo su - sauron /etc/init.d/romillot status"
/bin/bash: sudo: No such file or directory


[email protected]:~/.ssh$ ssh [email protected] "/bin/bash /usr/bin/sudo su - sauron /etc/init.d/romillot status"
/bin/bash: /usr/bin/sudo: Permission denied

As i said , i am a complete newbie

Offline Mark Greaves (PCNetSpec)

  • Hero Member
  • *****
  • Posts: 18277
  • Karma: 479
  • Gender: Male
  • "-rw-rw-rw-" .. The Number Of The Beast
    • View Profile
    • Awards
Re: sudo within ssh remote
« Reply #1 on: July 23, 2018, 03:30:33 pm »
Maybe try
Code: [Select]
ssh [email protected] "/bin/bash -c 'sudo su - sauron /etc/init.d/romillot status'"
WARNING: You are logged into reality as 'root'
logging in as 'insane' is the only safe option.

The Linux Community Forum

Re: sudo within ssh remote
« Reply #1 on: July 23, 2018, 03:30:33 pm »


SimplePortal 2.3.3 © 2008-2010, SimplePortal