0

Using below function I can connect to my Linux machine. But few commands need root permission to execute and direct root login is disabled. Also, the user cannot sudo.

require 'net/ssh'
def sshutm(host,un,pwd,cmd)
  Net::SSH.start( host, un, :password => pwd ) do|ssh|
    result = ssh.exec!(cmd)
    return result
  end
end

I tried this but it dint work.

def sshutm(host,un,pwd,cmd)
  Net::SSH.start( host, un, :password => pwd ) do|ssh|
    ssh.exec!("su")
    ssh.exec!("passowrd")
    result = ssh.exec!(cmd)
    return result
  end
end
Felix
  • 4,510
  • 2
  • 31
  • 46
Aniket
  • 67
  • 1
  • 5
  • 1
    Take a look at [this](http://stackoverflow.com/questions/11882776/ruby-net-ssh-calling-bash-script-with-interactive-prompts) question. It might help you. – user2422869 Sep 17 '14 at 10:56
  • possible duplicate of [ruby ssh: interactive command "su": How further after successfull logged in?](http://stackoverflow.com/questions/3061648/ruby-ssh-interactive-command-su-how-further-after-successfull-logged-in) – Felix Sep 17 '14 at 14:22

1 Answers1

0

You could make your user a sudo user (e.g. http://www.linux.com/learn/tutorials/306766:linux-101-introduction-to-sudo), and execute the given command with sudo (e.g. sudo ls /root). Details vary on the used distribution.

Felix
  • 4,510
  • 2
  • 31
  • 46
  • It was a sudo user before. But now due to security reasons it has been removed from sudoers list. – Aniket Sep 17 '14 at 10:28