Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running remote commands after vagrant ssh

Tags:

ssh

vagrant

vagrant ssh -- EXTRA SSH ARGS is supposed to allow extra args to be passed to ssh.

vagrant ssh -- -t 'cd /var/www' should ssh into vagrant and change directory to /var/www, but doesn't. Instead it returns

ssh: Could not resolve hostname ls: nodename nor servname provided, or not known

What am I missing?

like image 726
kayaker243 Avatar asked Mar 20 '14 03:03

kayaker243


People also ask

What is vagrant ssh command?

Command: vagrant ssh [name|id] [-- extra_ssh_args] This will SSH into a running Vagrant machine and give you access to a shell. On a simple vagrant project, the instance created will be named default.

How do I exit vagrant ssh?

Vagrant SSH Once you are done exploring the virtual machine, you can exit the session with CTRL-D.


2 Answers

This works for me:

vagrant ssh -- -t 'cd /var/www; /bin/bash' 
like image 188
Emyl Avatar answered Sep 26 '22 04:09

Emyl


To run a command to a vagrant box remotelly run:

vagrant ssh -c "COMMAND; COMMAND1" 

If you need, try vagrant ssh --help

like image 43
Bruno Gerotto Avatar answered Sep 24 '22 04:09

Bruno Gerotto