How to ssh to vagrant without actually running “vagrant ssh”?

后端 未结 16 1539
清酒与你
清酒与你 2020-11-29 15:07

I would like to reproduce the way Vagrant logs in to my VM within a shell script using an ssh command, so I create an alias to my Vagrant instance.

What

16条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-29 15:47

    You can add ssh config for your vagrant host to ssh config.

    1. Get ssh config for vagrant machine in vagrant folder: vagrant ssh-config

    2. Open {UserDir}/.ssh/config and append there result from the previous command. Note: the first line Host default mean the alias which you will use later for ssh command. Name it as your vagrant machine or dir. If you have only one vagrant dir - you can name it Host vagrant

    3. Ssh to vagrant: ssh vagrant. The last name is alias from the previous step.

提交回复
热议问题