作为root用户默认login
问题:我经常input的第一个命令是su -
。
问题:我如何使vagrant ssh
默认使用root用户?
版本:stream浪者1.6.5
解:
将以下内容添加到您的Vagrantfile
:
config.ssh.username = 'root' config.ssh.password = 'vagrant' config.ssh.insert_key = 'true'
当你从此vagrant ssh
,你会以root
身份login,并期望以下内容:
==> mybox: Waiting for machine to boot. This may take a few minutes... mybox: SSH address: 127.0.0.1:2222 mybox: SSH username: root mybox: SSH auth method: password mybox: Warning: Connection timeout. Retrying... mybox: Warning: Remote connection disconnect. Retrying... ==> mybox: Inserting Vagrant public key within guest... ==> mybox: Key inserted! Disconnecting and reconnecting using new SSH key... ==> mybox: Machine booted and ready!
更新2015年6月23日:这也适用于版本1.7.2。 键控安全性自1.7.0提高; 这种技术将覆盖回到之前使用已知私钥的方法。 此解决scheme不打算用于公开访问的盒子,没有在发布之前完成适当的安全措施。
参考:
这很有用:
sudo passwd root
对于那些因为需要在stream浪汉中设置root密码而被捕的人,
这工作,如果你在Ubuntu / Trusty64框:
vagrant ssh
一旦你在Ubuntu的框中:
sudo su
现在你是root用户。 您可以更新根密码,如下所示:
sudo -i passwd
现在在/etc/ssh/sshd_config
文件中编辑下面的行
PermitRootLogin yes
另外,创build自己的备用用户名是很方便的:
adduser johndoe
等到它要求input密码。
不要忘记root根目录才能login!
将configuration代码放在/ etc / ssh / sshd_config文件中。
PermitRootLogin yes
如果Vagrantfile
如下所示:
config.ssh.username = 'root' config.ssh.password = 'vagrant' config.ssh.insert_key = 'true'
但是stream浪者仍然问你root密码,很有可能你使用的基础盒子没有configuration为允许rootlogin。
例如,官方的ubuntu14.04框不在/etc/ssh/sshd_config
设置PermitRootLogin yes
。
所以如果你想要一个盒子可以以root身份默认login(只有Vagrantfile,没有更多的工作),你必须:
-
通过用户名
vagrant
设置一个vagrant
(不pipe名字,但是根) -
login并编辑sshdconfiguration文件。
ubuntu:编辑
/etc/ssh/sshd_config
,设置PermitRootLogin yes
orthers:….
(我只使用Ubuntu,随时添加其他平台的解决方法)
-
build立一个新的基地箱:
vagrant package --base your-vm-name
这个创build一个文件
package.box
-
添加那个基地箱子到stream浪汉:
vagrant box add ubuntu-root file:///somepath/package.box
那么,你需要使用这个基础框来构build允许以root身份进行自动login的vm。
-
通过
vagrant destroy
破坏原始的vagrant destroy
-
编辑原始的
Vagrantfile
,将文件名称更改为ubuntu-root
和用户名为root
,然后build立一个新的。
我花了一些时间才弄清楚,这在我看来太复杂了。 希望stream浪汉会改善这一点。
我知道这是一个古老的问题,但看着原来的问题,它看起来像用户只是想以root身份运行一个命令..这就是我在寻找答案时所需要做的,并偶然发现了问题。
所以这个值得我的意见:
stream浪ssh servername -c“echo vagrant | sudo -S shutdown 0”
“vagrant”是sudo命令中回显的密码,因为众所周知,无业游民帐户有sudo privilages,当你sudo的时候,你需要指定用户帐户的密码,而不是根目录。默认情况下,stream浪用户的密码是“stream浪”!
默认情况下,你需要root权限closures,所以我想做一个关机是一个很好的testing。
显然你不需要指定一个服务器名称,如果只有一个stream浪环境。 另外,我们正在谈论当地stream浪的虚拟机器,所以我没有看到任何安全问题。
希望这可以帮助。
vagrant destroy vagrant up
请将此添加到stream浪文件中:
config.ssh.username = 'vagrant' config.ssh.password = 'vagrant' config.ssh.insert_key = 'true'