Linux 创建符号链接:协议错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17895256/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-07 00:23:25  来源:igfitidea点击:

creating symbolic link: Protocol error

linuxwindowsvirtual-machinefile-permissionssymlink

提问by TroodoN-Mike

I have created linux (Centos) on my virtual box. When I ssh to it and I try to create symbolic link (on my shared folder with full access):

我在我的虚拟机上创建了 linux (Centos)。当我通过 ssh 连接它并尝试创建符号链接时(在具有完全访问权限的共享文件夹上):

ln -s path/folder/example myFolder

I get error:

我得到错误:

ln: creating symbolic link `myFolder': Protocol error

Is there any reason or solution to this?

有什么原因或解决方案吗?

采纳答案by Paul Dixon

It's a problem with the host filesystem. Check the permissions on the host folder are adequate and the the host filesystem supports symlinks.

这是主机文件系统的问题。检查主机文件夹的权限是否足够,并且主机文件系统支持符号链接。

回答by Angela Zenner

Right click on your command prompt and "Run as Administrator" (or whatever program you're using to make those symlinks needs to be run as adminstrator).

右键单击您的命令提示符和“以管理员身份运行”(或您用来制作这些符号链接的任何程序都需要以管理员身份运行)。

回答by Hector GR

Here is the solution in a ticket on virtualbox.org : https://www.virtualbox.org/ticket/10085#comment:32(Note: Execute "whoami /priv" in console with Administrative privileges)

以下是 virtualbox.org 票证中的解决方案:https: //www.virtualbox.org/ticket/10085#comment: 32(注意:在具有管理权限的控制台中执行“whoami /priv”)

I have done some Windows research on this bug.

If your user is of the Administrator type (rather than a Standard account), there's no way to run VB with symlinks working without the UAC prompt.

If you have a Standard user account (or if you are willing to switch your account to Standard and create a separate Admin account), the solution exists. You will, however, need admin privileges to accomplish several of the steps (not necesarrily for your user account).

  1. Run the Local Security Policy (Win+R, type "secpol.msc", confirm UAC). Then navigate to "Local Policies->User Rights Assignment".
  2. Find the permission called "Create symbolic links" and double-click it. Add your user to the list of objects having this permission. Or you can add the "Users" group. Log off and log on. You can check the success by running in console:

    whoami /priv
    

    If you see the privilege SeCreateSymbolicLinkPrivilege enabled, you've done well.

  3. Make sure your user has proper access to the shared folder on host system.

  4. As mentioned here earlier, execute

    VBoxManage setextradata VM_NAME VBoxInternal2/SharedFoldersEnableSymlinksCreate/SHARE_NAME 1
    

    in a console from the C:\Program Files\VirtualBox folder. Don't forget to substitute VM_NAME with the name of your VM and SHARE_NAME with the name of the shared folder (as it appears in the VM settings).

  5. You're done.

If you happen to own one of the "lesser" version of windows (e.g. 7 Home), you don't have the "secpol.msc" utility. See How do I grant SeCreateSymbolicLink on Windows Vista Home editionfor help.

我对这个错误做了一些 Windows 研究。

如果您的用户是管理员类型(而不是标准帐户),则无法在没有 UAC 提示的情况下使用符号链接运行 VB。

如果您有一个标准用户帐户(或者如果您愿意将您的帐户切换到标准并创建一个单独的管理员帐户),则存在解决方案。但是,您将需要管理员权限才能完成几个步骤(对于您的用户帐户来说不是必需的)。

  1. 运行本地安全策略(Win+R,输入“secpol.msc”,确认 UAC)。然后导航到“本地策略-> 用户权限分配”。
  2. 找到名为“创建符号链接”的权限并双击它。将您的用户添加到具有此权限的对象列表中。或者您可以添加“用户”组。注销并登录。您可以通过在控制台中运行来检查是否成功:

    whoami /priv
    

    如果您看到权限 SeCreateSymbolicLinkPrivilege 已启用,则说明您做得很好。

  3. 确保您的用户可以正确访问主机系统上的共享文件夹。

  4. 正如前面提到的,执行

    VBoxManage setextradata VM_NAME VBoxInternal2/SharedFoldersEnableSymlinksCreate/SHARE_NAME 1
    

    在 C:\Program Files\VirtualBox 文件夹的控制台中。不要忘记将 VM_NAME 替换为您的 VM 的名称,并将 SHARE_NAME 替换为共享文件夹的名称(如 VM 设置中所示)。

  5. 你完成了。

如果您碰巧拥有 Windows 的“较小”版本之一(例如 7 Home),则您没有“secpol.msc”实用程序。请参阅 如何在 Windows Vista 家庭版上授予 SeCreateSymbolicLink 以获取帮助。

回答by Tanuj Jain

find the cmd.exe file. Right click on the cmd.exe . Select "Run as Administrator" menu option. It should work perfectly.

找到 cmd.exe 文件。右键单击 cmd.exe 。选择“以管理员身份运行”菜单选项。它应该可以完美运行。

回答by cancerbero

As I understand, Windows VirtualBox hosts doesn't support links (from https://www.virtualbox.org/manual/ch04.html#sharedfolders)

据我了解,Windows VirtualBox 主机不支持链接(来自https://www.virtualbox.org/manual/ch04.html#sharedfolders

Starting with version 4.0, VirtualBox shared folders also support symbolic links (symlinks), under the following conditions:

The host operating system must support symlinks (i.e. a Mac, Linux or Solaris host is required).

Currently only Linux and Solaris Guest Additions support symlinks.

For security reasons the guest OS is not allowed to create symlinks by default. If you trust the guest OS to not abuse the functionality, you can enable creation of symlinks for "sharename" with:

VBoxManage setextradata "VM name" VBoxInternal2/SharedFoldersEnableSymlinksCreate/sharename 1

从 4.0 版本开始,VirtualBox 共享文件夹也支持符号链接(symlinks),在以下条件下:

主机操作系统必须支持符号链接(即需要 Mac、Linux 或 Solaris 主机)。

目前只有 Linux 和 Solaris Guest Additions 支持符号链接。

出于安全原因,默认情况下不允许来宾操作系统创建符号链接。如果您相信来宾操作系统不会滥用该功能,您可以使用以下命令为“共享名”创建符号链接:

VBoxManage setextradata "VM 名称" VBoxInternal2/SharedFoldersEnableSymlinksCreate/sharename 1

回答by Ukr

By default VirtualBox VM disables creation of symbolic links.

默认情况下 VirtualBox VM 禁用符号链接的创建。

Oracle VM VirtualBox shared folders support symbolic links under the following conditions:

Oracle VM VirtualBox 共享文件夹在以下条件下支持符号链接:

  • The host operating system must support symlinks. For example, a Mac OS X, Linux, or Oracle Solaris host is required.
  • Currently only Linux and Oracle Solaris Guest Additions support symlinks.
  • For security reasons the guest OS is not allowed to create symlinks by default.
  • 主机操作系统必须支持符号链接。例如,需要 Mac OS X、Linux 或 Oracle Solaris 主机。
  • 目前只有 Linux 和 Oracle Solaris Guest Additions 支持符号链接。
  • 出于安全原因,默认情况下不允许来宾操作系统创建符号链接。

To enable creation of symlinks for a shared folder you should do:

要为共享文件夹创建符号链接,您应该执行以下操作:

  1. Run this command on your host (where {VM_name} is the name of VM and {share_folder_name} is the name of shared directory):
  1. 在您的主机上运行此命令(其中 {VM_name} 是 VM 的名称,{share_folder_name} 是共享目录的名称):
$ VBoxManage setextradata "{VM_name}" VBoxInternal2/SharedFoldersEnableSymlinksCreate/{share_folder_name} 1

In my case it looks like:

就我而言,它看起来像:

$ VBoxManage setextradata "ubuntu16" VBoxInternal2/SharedFoldersEnableSymlinksCreate/shared 1
  1. Reboot the VM.
  1. 重新启动虚拟机。

More information you can find here:

您可以在此处找到更多信息:

https://docs.oracle.com/cd/E97728_01/E97727/html/sharedfolders.htmlhttps://www.virtualbox.org/ticket/18572?cversion=0&cnum_hist=2

https://docs.oracle.com/cd/E97728_01/E97727/html/sharedfolders.html https://www.virtualbox.org/ticket/18572?cversion=0&cnum_hist=2

回答by Purnesh Dixit

Basically you need to again tell VirtualBox to enable symlinks. Here's the complete solution

基本上你需要再次告诉 VirtualBox 启用符号链接。这是完整的解决方案

Have this in your vagrant file,

在你的流浪文件中有这个,

config.vm.provider "virtualbox" do |v|
    v.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/Folder_Name", "1"]
end

I recommended comment out any sync folder and let default ./(at host) synced at /vagrant(at guest). This will make sure your shared folder(Folder_Name)name is always vagrantas mentioned here https://www.vagrantup.com/docs/synced-folders/. Also, you won't face issues with ssh

我建议注释掉任何同步文件夹,并让默认 ./(at host) 在 /vagrant(at guest) 同步。这将确保您的共享文件夹(Folder_Name)名称始终是vagrant,如此处https://www.vagrantup.com/docs/synced-folders/ 所述。此外,您不会遇到 ssh 问题

If the symlink protocol error returns after restart or still persists run

如果符号链接协议错误在重启后返回或仍然持续运行

VBoxManage setextradata "VM_Name" VBoxInternal2/SharedFoldersEnableSymlinksCreate/Folder_Name 1

vagrant halt
vagrant up

vagrant ssh

Usually, VBoxManagee is located at C:\Program Files\Oracle\VirtualBox\

通常,VBoxManagee 位于 C:\Program Files\Oracle\VirtualBox\

Verify working of symlink by going to /vagrant and running

通过转到 /vagrant 并运行来验证符号链接的工作

touch test.txt && ln -s test.txt test1.txt

PS: I have tried this on Windows Home which has limited accessibility to security settings

PS:我在 Windows Home 上尝试过这个,它对安全设置的可访问性有限