Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

It should a simple question.

I had a vagrant box there, where I can start vagrant ssh to access without password.

And how can I remotely execute ssh command to get some result like below, which can be used in jenkins CI server to check something.

$ vagrant ssh 'who -a' 

My environment

  • Vagrant 0.8.7
  • Ubuntu 11.04 (host)
share|improve this question

migrated from stackoverflow.com Oct 20 '11 at 11:05

This question came from our site for professional and enthusiast programmers.

add comment

3 Answers

The following should work; for more information check out man vagrant, man ssh and man who.

vagrant ssh -c "who -a"
share|improve this answer
add comment

You could also use the following to see the ssh config behind the vagrant ssh command:

vagrant ssh-config

Note: This will only work once you did vagrant up.

Then use the ip, port, key, etc. in your own ssh command:

ssh -i /path/to/vagrant/keyfile vagrant@ip:port who -a
share|improve this answer
add comment

To execute complex commands in Jenkins i prefer the following syntax

vagrant ssh -- who -a

where everything after the '--' is passed as a command to the VM's shell.

From http://docs.vagrantup.com/v2/cli/ssh.html:

If a -- (two hyphens) are found on the command line, any arguments after this are passed directly into the ssh executable.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.