Home > bash, vagrant > sshpass

sshpass

Problem:
Once again, portforwarding port 3141 on one vagrant box, to point to a local devpi-server running on another vagrant box has gotten tiring. I need to be able have this functionality on any vagrant box I provision.

Solution:
Moved the command to a script. This may not be a secure way of doing this, but it suffices for now as this is only for local development work. This is not intended for work on remote production or staging servers.

1. Install sshpass

$ sudo apt-get install sshpass

2. Put the command in a script file (port3141.sh).

#!/bin/bash

cd /home/vagrant

export SSHPASS="vagrant"

sshpass -e  ssh -L 3141:192.168.1.2:3141 -o LogLevel=Error -o StrictHostKeyChecking=no vagrant@192.168.1.2

3. Make it executable

$ chmod +x port3141.sh

4. Now everytime I need to port forward I simply open up a separate tmux window and run the script.

Note:
Only changing StrictHostKeyChecking because of my frequency of using a new box. Change with caution.

StrictHostKeyChecking
If this flag is set to “yes”, ssh(1) will never automatically add host keys to the ~/.ssh/known_hosts file, and refuses to connect to hosts whose host key has changed. This pro‐
vides maximum protection against trojan horse attacks, though it can be annoying when the /etc/ssh/ssh_known_hosts file is poorly maintained or when connections to new hosts are
frequently made. This option forces the user to manually add all new hosts. If this flag is set to “no”, ssh will automatically add new host keys to the user known hosts files.
If this flag is set to “ask”, new host keys will be added to the user known host files only after the user has confirmed that is what they really want to do, and ssh will refuse to
connect to hosts whose host key has changed. The host keys of known hosts will be verified automatically in all cases. The argument must be “yes”, “no”, or “ask”. The default is
“ask”.

Source:
http://stackoverflow.com/questions/4780893/use-expect-in-bash-script-to-provide-password-to-ssh-command

Advertisements
Categories: bash, vagrant Tags: ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s