我做了一个 vagrant up
流浪汉箱上 StefanScherer/windows_2019 (vmware_desktop, 2020.02.12)
并安装SSH服务器,通过 "Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0"
服务器启动并正常工作,但用户 vagrant
无法连接,既不能从虚拟机内部(ssh [email protected])连接,也不能从外部连接。它说权限被拒绝。我用 vagrant
作为密码,与我用来登录虚拟机的密码相同。
我创建了另一个用户 asdf
而我却能很好地与这个用户建立联系。所以这与用户 vagrant
. 运转 Get-LocalUser
显示用户之间没有差异 vagrant
和我新创建的用户 asdf
PS C:\Windowssystem32> Get-LocalUser
Name Enabled Description
---- ------- -----------
Administrator True Built-in account for administering the computer/domain
asdf True
DefaultAccount False A user account managed by the system.
Guest False Built-in account for guest access to the computer/domain
sshd True
vagrant True Vagrant User
WDAGUtilityAccount False A user account managed and used by the system for Windows Defender Application Guard scen...
两个账户均为类型 LocalUser
.为什么也不工作 vagrant
? 我怎么才能找出这个账号的特别之处呢?
问题是 这个毛病 在openssh for Windows中。主机名(computername)必须和用户名不一样。在我的例子中,这两个都是vagrant。
你可以通过修改你的 Vagrantfile
和设置 config.vm.hostname
变成一个与 vagrant
. 另外,您也可以在虚拟机内部更改主机名,例如,在Powershell中通过 Rename-Computer -NewName foo -Force -PassThru
(需要重新启动)。