0

Why would net-ssh not be able to execute the useradd command?

This is my net-ssh code:

Net::SSH.start(host, user, forward_agent: true) do |ssh|
  ssh.open_channel do |ch|
    ch.request_pty
    ch.exec "mkdir /tmp/unicorn"
    ch.exec "sudo groupadd unicorn"
    ch.exec "sudo chgrp unicorn /tmp/unicorn"
    ch.exec "sudo useradd application" do |ch, success|
      if success
        puts 'command worked'
      else
        puts 'command failed'
      end
    end
  end
end

All of the commands work except for the useradd command. I can log in and run the useradd command and a user is added.

Thanks, Eric

1 Answer 1

1

I would modify your script to add the command

puts ch.exec "sudo which useradd"

To see if it is a path problem.

I would also add

ch.exec 'sudo useradd application 1>/tmp/useradd.log 2>&1'

And then go look on the target box to see if there were any errors logged in the /tmp/useradd.log file.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.