Closed dogi closed 8 years ago
Change Vagrantfile so that the reverse of standard password vagrant
is the new password.
So, you want to insert this inside Vagrantfile?
config.ssh.password = "tnargav"
Not sure if I get your point correctly.
I am on some communities exposing ports to the big internet ;)
@xinglunxu : where exactly in the "Vagrantfile" to I have to put that in ... context is missing ;(
Here is the reference to how to configure the ssh connection from vagrant to the vm
To change the ssh password, we can just put the setting
config.ssh.password = "tnargav"
anywhere under
Vagrant.configure(2) do |config|
@xinglunxu thx
you have the go for it ;)
@dogi So After I inserted this line and tried to reload the machine, an error like this happened.
I still haven't figure out how to solve it. But before that, may I ask why are we changing the password of the vagrant ssh? What is the problem we are trying to solve in this issue post? I looked at the link from https://github.com/dogi/ole--vagrant-community/issues/2#issue-157220242 But I still didn't get the problem. :sweat_smile:
Yo, I finally found a way to change the password for ssh by script. But I am almost positive that there is a better way to do this.
So previously, I tried to add config.ssh.password = "tnargav"
into Vagranfile to change the ssh password for vagrant. However, all it does is just change the password that Vagrant uses to ssh the vm. The ssh password of user vagrant will still be unchanged in the vm. That is why there is a connection problem in my previous post.
IMHO, the password setting for ssh is included in the "ole/jessie64" box. Since I cannot find a good way to configure it in Vagrantfile, I decided to change the ssh password after the vm is set up and run using a script file. It looks like this:
#!/bin/bash
VM_ID=`vagrant global-status | grep community | cut -d' ' -f1`
KEYPATH=`vagrant ssh-config ${VM_ID} | grep "IdentityFile" | cut -d' ' -f4`
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
ssh -i ${KEYPATH} vagrant@127.0.0.1 -p 2222 'bash -s' < ${DIR}/command.sh
This script ssh to the vm and run a local script to change the password.
The local script is like this.
#!/bin/bash
echo -e "<currentpassword>\n<newpassword>\n<newpassword>" | passwd vagrant
Since I changed the password after the vm is set tup, this solution will be system dependent.
@xinglunxu awesome :)
will use this script for the ole template creation ... https://atlas.hashicorp.com/ole/boxes/jessie64 so that later we can just use the easy way of changing the password
Ok, I will modify it a little bit more later. Now it assume that the vagrant is using port 2222 for ssh. I should get it from the "vagrant ssh-config" command instead. Also, it is assuming that the name of the vm is "community". I should make it an argument for the script.
As promised, here is the improved version of the script The comments inside the script already describe the behavior of it in detail
#!/bin/bash
#Run this script with the machine name to which you want to change the password.
#Run it with "community" for development environment and "ole" for production environment
#Example: "sh changepassword.sh community"
#parse the name of the vm machine from command line argument
VM_NAME=$1
VM_ID=`vagrant global-status | grep ${VM_NAME} | cut -d' ' -f1`
KEYPATH=`vagrant ssh-config ${VM_ID} | grep "IdentityFile" | cut -d' ' -f4`
PORT=`vagrant ssh-config ${VM_ID} | grep "Port" | cut -d' ' -f4`
#connect to vm and change password from "vagrant" to "openlearning" replace "openlearning" with your customized password
ssh -i ${KEYPATH} vagrant@127.0.0.1 -p ${PORT} "echo -e \"vagrant\nopenlearning\nopenlearning\" | passwd vagrant"
I combined the previous two scripts into one. Also the the script now take the name of target vm as command line argument. The port number is also no longer hardcoded. It is parsed from "vagrant ssh-config".
The testing process is as easy as following
sh changepassword.sh community
You can just copy and paste the code above then run it from any directory. To manually ssh to the "community" machine using a password, type the following command
ssh vagrant@127.0.0.1 -p 2222
then type the current password when prompt.
Please comment here or gitter if something go wrong or if there is any question. Thanks!
Is there a fork or branch of the entire repo? I have a mac and I'd like to give it a shot.
@sente Hi, I haven't make a pull request yet, but I think you can just copy and paste the code into any directory and run it as in the post. It is designed to run in any directory.
I don't currently use vagrant/docker on my mac so I'd be running the whole shebang from start to finish. It's good practice to use forks/branches anyways, in my opinion.
@sente This is my own fork of the ole--vagrant--community https://github.com/xinglunxu/ole--vagrant-community And I just pushed the changepassword.sh script to it. It is under the macosx directory. There is only one branch there. Is this something you are looking for?
@xinglunxu I tried and yes it works. Cheers
done with update -https://github.com/dogi/ole--vagrant-community/commit/defdf1dc18f3f8190faf462e532ebfd330fc1d84 which updates to version 0.1.4 of ole/jessie64
the change happens in https://github.com/dogi/ole--vagrant-template/commit/dd489c3b06088f7c92b6e65188ba40d8de9cee3c
http://stackoverflow.com/questions/22575261/vagrant-stuck-connection-timeout-retrying