아래 기능을 사용하여 Linux 컴퓨터에 연결할 수 있습니다. 그러나 실행하기 위해 루트 권한이 필요한 명령은 거의 없으며 루트 로그인을 직접 사용할 수 없습니다. 또한 사용자는 sudo를 할 수 없습니다.ruby 및 net/ssh를 사용하여 Linux에서 사용자를 전환하려면 어떻게해야합니까?
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
시도해 보았지만 제대로 작동하지 않았습니다.
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
질문 [this] (http://stackoverflow.com/questions/11882776/ruby-net-ssh-calling-bash-script-with-interactive-prompts) 질문을보십시오. 도움이 될지도 모릅니다. – user2422869
가능한 복제본 [ruby ssh : interactive command "su": 성공한 로그인 후 얼마나?] (http://stackoverflow.com/questions/3061648/ruby-ssh-interactive-command-su-how-further-after -successfull-logged-in) – Felix