Vagrant ssh, default folder + default commands

238 views
Skip to first unread message

Alan

unread,
Jun 28, 2017, 1:34:36 PM6/28/17
to Vagrant
Hi all,

I was wondering if there was a way when (everytime) I do 'vagrant ssh', to execute the following two commands automatically:

sudo su    (to change the user from vagrant to root automatically).
cd /blah/blah/

Or, a way for when doing vagrant ssh, to become 'root' and then be in a particular directory.

Box: Ubuntu

Thank you,
Alan.

Alvaro Miranda Aguilera

unread,
Jun 28, 2017, 7:51:55 PM6/28/17
to vagra...@googlegroups.com
hi

vagrant ssh -c 'sudo su - ; cd /blah/blah'

?

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/vagrant/issues
IRC: #vagrant on Freenode
---
You received this message because you are subscribed to the Google Groups "Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vagrant-up+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/4d63e54f-84ab-49d0-9fd7-d4727bc371b5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Alvaro

Alan

unread,
Jun 29, 2017, 4:45:01 AM6/29/17
to Vagrant
Close, but it's not what I'm looking for as it's not really automatic, because the user typing it has to type those specific arguments everytime they `vagrant ssh`.


On Thursday, 29 June 2017 00:51:55 UTC+1, Alvaro Miranda Aguilera wrote:
hi

vagrant ssh -c 'sudo su - ; cd /blah/blah'

?
On Wed, Jun 28, 2017 at 7:34 PM, Alan <alan...@gmail.com> wrote:
Hi all,

I was wondering if there was a way when (everytime) I do 'vagrant ssh', to execute the following two commands automatically:

sudo su    (to change the user from vagrant to root automatically).
cd /blah/blah/

Or, a way for when doing vagrant ssh, to become 'root' and then be in a particular directory.

Box: Ubuntu

Thank you,
Alan.

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/vagrant/issues
IRC: #vagrant on Freenode
---
You received this message because you are subscribed to the Google Groups "Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vagrant-up+...@googlegroups.com.



--
Alvaro

Alan

unread,
Jun 29, 2017, 5:14:53 AM6/29/17
to Vagrant
Your command doesn't change directory.


On Thursday, 29 June 2017 00:51:55 UTC+1, Alvaro Miranda Aguilera wrote:
hi

vagrant ssh -c 'sudo su - ; cd /blah/blah'

?
On Wed, Jun 28, 2017 at 7:34 PM, Alan <alan...@gmail.com> wrote:
Hi all,

I was wondering if there was a way when (everytime) I do 'vagrant ssh', to execute the following two commands automatically:

sudo su    (to change the user from vagrant to root automatically).
cd /blah/blah/

Or, a way for when doing vagrant ssh, to become 'root' and then be in a particular directory.

Box: Ubuntu

Thank you,
Alan.

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/vagrant/issues
IRC: #vagrant on Freenode
---
You received this message because you are subscribed to the Google Groups "Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vagrant-up+...@googlegroups.com.



--
Alvaro

Alan

unread,
Jun 29, 2017, 5:23:15 AM6/29/17
to Vagrant
Nevermind, I solved it.

I just add the appropriate commands (cd /vagrant_data, sudo su) to the bashrc file.

Antony Stone

unread,
Jun 29, 2017, 5:25:08 AM6/29/17
to vagra...@googlegroups.com
On Thursday 29 June 2017 at 11:14:53, Alan wrote:

> Your command doesn't change directory.

It does, but it then reverts to the login directory when the command ends.

Everything inside the ' quotation marks after the "-c" runs in a shell
environment.

At the end of the ' quotation marks that environment is exited and the user is
back to their standard login shell. You can prove this if you like by adding
one more command:

vagrant ssh -c 'sudo su - ; cd /blah/blah ; touch newfile'


It sounds to me as though you might be better off putting these commands into
the user's login profile inside the Vagrant box, rather than trying to add them
from the outside?


Antony.

> On Thursday, 29 June 2017 00:51:55 UTC+1, Alvaro Miranda Aguilera wrote:
> > hi
> >
> > vagrant ssh -c 'sudo su - ; cd /blah/blah'
> >
> > ?
> >
> > On Wed, Jun 28, 2017 at 7:34 PM, Alan <alan...@gmail.com <javascript:>>
> >
> > wrote:
> >> Hi all,
> >>
> >> I was wondering if there was a way when (everytime) I do 'vagrant ssh',
> >> to execute the following two commands automatically:
> >>
> >> sudo su (to change the user from vagrant to root automatically).
> >> cd /blah/blah/
> >>
> >> Or, a way for when doing vagrant ssh, to become 'root' and then be in a
> >> particular directory.
> >>
> >> Box: Ubuntu
> >>
> >> Thank you,
> >> Alan.

--
You can spend the whole of your life trying to be popular,
but at the end of the day the size of the crowd at your funeral
will be largely dictated by the weather.

- Frank Skinner

Please reply to the list;
please *don't* CC me.
Reply all
Reply to author
Forward
0 new messages