Ivan_C
(Ivan C.)
5 October 2011 08:45
1
Hi,
i am trying to ssh to a server and execute some commands. To do that, i
need to become a root user and somehow it does not work with below.
ssh = Net::SSH.start("host", "user", :password =>"xxxx")
ssh.exec!('sudo su -')
ssh.exec!('xxxx')
txt = ssh.exec!('ls -al')
puts txt
By executing ls -al as a test, the returns are not based on the root
permission. My guess is the sudo su - does not actually works.
Please advise
···
--
Posted via http://www.ruby-forum.com/ .
A simpler test case:
ssh = Net::SSH.start("host", "user", :password =>"xxxx")
puts ssh.exec!('ls -la /root')
puts ssh.exec!('sudo ls -la /root')
Running sudo over ssh generally requires that a pseudo-tty be allocated:
$ ssh XXX ls -la /root
ls: /root: Permission denied
$ ssh XXX sudo ls -la /root
sudo: sorry, you must have a tty to run sudo
$ ssh -t XXX sudo ls -la /root
drwxr-x--- 7 root root 4096 Sep 22 12:20 .
drwxr-xr-x 25 root root 4096 Sep 16 14:49 ..
-rw------- 1 root root 1856 Jun 8 14:41 anaconda-ks.cfg
···
On Wed, Oct 5, 2011 at 4:45 AM, Ivan C. <ivanchung84@gmail.com> wrote:
i am trying to ssh to a server and execute some commands. To do that, i
need to become a root user and somehow it does not work with below.
ssh = Net::SSH.start("host", "user", :password =>"xxxx")
ssh.exec!('sudo su -')
ssh.exec!('xxxx')
txt = ssh.exec!('ls -al')
puts txt
By executing ls -al as a test, the returns are not based on the root
permission. My guess is the sudo su - does not actually works.
unknown wrote in post #1025130:
permission. My guess is the sudo su - does not actually works.
A simpler test case:
ssh = Net::SSH.start("host", "user", :password =>"xxxx")
puts ssh.exec!('ls -la /root')
puts ssh.exec!('sudo ls -la /root')
Running sudo over ssh generally requires that a pseudo-tty be allocated:
$ ssh XXX ls -la /root
ls: /root: Permission denied
$ ssh XXX sudo ls -la /root
sudo: sorry, you must have a tty to run sudo
$ ssh -t XXX sudo ls -la /root
drwxr-x--- 7 root root 4096 Sep 22 12:20 .
drwxr-xr-x 25 root root 4096 Sep 16 14:49 ..
-rw------- 1 root root 1856 Jun 8 14:41 anaconda-ks.cfg
i am trying to ssh to a server and execute some commands. To do that, i
need to become a root user and somehow it does not work with below.
So, if your interest is in learning/playing with Net::SSH, carry on.
Another cool tool for this sort of thing is 'expect', i'm sure there is
a ruby lib for expect but I've never used it.
If you are trying to get some work done, another approach is to edit the
sudoers file on the remote host.
Add the commands that you want your unprivileged user to be able to
execute (or put them all in an executable .sh file). for this you may
want the nopassword option.
···
On Wed, Oct 5, 2011 at 4:45 AM, Ivan C. <ivanchung84@gmail.com> wrote:
--
Posted via http://www.ruby-forum.com/\ .
Ivan_C
(Ivan C.)
6 October 2011 08:11
4
unknown wrote in post #1025130:
permission. My guess is the sudo su - does not actually works.
A simpler test case:
ssh = Net::SSH.start("host", "user", :password =>"xxxx")
puts ssh.exec!('ls -la /root')
puts ssh.exec!('sudo ls -la /root')
Running sudo over ssh generally requires that a pseudo-tty be allocated:
$ ssh XXX ls -la /root
ls: /root: Permission denied
$ ssh XXX sudo ls -la /root
sudo: sorry, you must have a tty to run sudo
$ ssh -t XXX sudo ls -la /root
drwxr-x--- 7 root root 4096 Sep 22 12:20 .
drwxr-xr-x 25 root root 4096 Sep 16 14:49 ..
-rw------- 1 root root 1856 Jun 8 14:41 anaconda-ks.cfg
Well, when i execute
puts ssh.exec!('ssh -t user@host ls -la /root')
It gives:
Pseudo-terminal will not be allocated because stdin is not a terminal.
Permission denied, please try again.
Permission denied, please try again.
Permission denied (publickey,gssapi-with-mic,password).
After i google around and execute this
puts ssh.exec!('ssh -t -t user@host ls -la /root')
It gives:
Permission denied, please try again.
Permission denied, please try again.
Permission denied (publickey,gssapi-with-mic,password).
Seems like it's requesting password. How do send passsord?
···
On Wed, Oct 5, 2011 at 4:45 AM, Ivan C. <ivanchung84@gmail.com> wrote:
--
Posted via http://www.ruby-forum.com/\ .