如何判断我是否在Vagrant主机中? [英] How to tell if I am inside a Vagrant host?

查看:93
本文介绍了如何判断我是否在Vagrant主机中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

确定我是否在无业游民的机器中运行的防弹方法是什么?

Whats a bulletproof way to determine if I am running inside a vagrant machine?

来宾操作系统是Debian Linux,但是如果每个操作系统都有指标的话,也可以很好地记录下来.

Guest OS is Debian Linux, though if there are indicators per-os that would be great to have documented as well.

推荐答案

提供一个可以检查是否存在的文件似乎是处理此问题的最可靠方法.

Provisioning a file that you can check the existence of seems like the most reliable way to handle this.

如果不想将文件写入框中,另一种选择是检查vagrant用户本身是否存在:

Another option if you don't want to write files to the box would be to check for the existence of the vagrant user itself:

grep -q '^vagrant:' /etc/passwd && echo 'Vagrant environment: true'

这并非像其他人所指出的那样万无一失,并且有可能(虽然不常见)有一个无聊的盒子,使用不同的用户进行连接.

This is not foolproof as others have indicated, and it is possible (although uncommon) to have a vagrant box that uses a different user to connect as.

如果您的环境中的计算机上有一个名为vagrant的用户帐户,而这些帐户实际上不是 流浪汉框,但检查用户的存在也无法可靠地进行,

Checking the user's existence also would not work reliably if you have machines in your environment with a user account called vagrant that are not actually vagrant boxes, but that would also be fairly uncommon.

这篇关于如何判断我是否在Vagrant主机中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆