From: brabuhr@... Date: 2011-10-05T21:55:27+09:00 Subject: Re: How to use 'net/ssh' to sudo su - On Wed, Oct 5, 2011 at 4:45 AM, Ivan C. 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. 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