It should be a simple question.

I had a vagrant box there, where I can start vagrant ssh to access it 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)

3 Answers 3


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

vagrant ssh -c "who -a"

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

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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