如何ssh到vagrant没有实际运行“vagrant ssh”? [英] How to ssh to vagrant without actually running "vagrant ssh"?
问题描述
我想重现一个Vagrant如何在shell脚本中使用 ssh
命令登录到我的VM,所以我创建一个别名到我的Vagrant实例。
I would like to reproduce the way how Vagrant logs to my VM within a shell script using ssh
command, so I create an alias to my Vagrant instance.
使用常规 ssh
命令访问它的命令语法是什么?
What is the command syntax to use the regular ssh
command to access it?
推荐答案
我不得不重新实现vagrant ssh,因为它的 -c
选项没有传递参数。这基本上是它的作用(可能有更多,但它工作正常这样)
I've had to re-implement "vagrant ssh" because it's -c
option didn't pass on arguments properly. This is basically what it does (there might be more, but it works fine this way)
#!/bin/sh
PORT=$(vagrant ssh-config | grep Port | grep -o '[0-9]\+')
ssh -q \
-o UserKnownHostsFile=/dev/null \
-o StrictHostKeyChecking=no \
-i ~/.vagrant.d/insecure_private_key \
vagrant@localhost \
-p $PORT \
"$@"
到kgadek):
ssh $(vagrant ssh-config | awk 'NR>1 {print " -o "$1"="$2}') localhost
要考虑当您有多个vagrant主机时,所需的主机,以及从配置(使用sed)剔除空行:
To account for when you have more than one vagrant host, this will select the desired host, as well as cull blank lines from the config (using sed):
HOST=name-of-my-host
ssh $(vagrant ssh-config $HOST | sed '/^[[:space:]]*$/d' | awk 'NR>1 {print " -o "$1"="$2}') localhost
这篇关于如何ssh到vagrant没有实际运行“vagrant ssh”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!