Netbeans将root设置为作者

内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用

  • 回答 (1)
  • 关注 (0)
  • 查看 (182)

我正在运行Linux Mint 18.3肉桂64位

我刚刚下载了Apache NetBeans IDE 9.0

没有必要运行任何脚本来安装它,我只需要运行以下命令来启动它:sudo /opt/netbeans/bin/netbeans 然后输入我的密码并打开netbeans。然后我为该程序制作了一个启动器,因为每次打开netbeans时我都不想输入命令和密码。但发射器没有用。我意识到我没有把“sudo”放在启动器执行的命令中,所以我把它放了。并没有奏效。

我认为它不起作用,因为启动器执行sudo /opt/netbeans/bin/netbeans但没有输入密码。经过一些研究后,我最终star_man ALL=(ALL) NOPASSWD: /opt/netbeans/bin/netbeans在最后加入/etc/sudoers并最终有效。但是当我创建一个新项目时,Netbeans将root设置为它创建的每个文件的作者。

例如,当我输入ls -l我的项目目录时,它会输出:

-rw-r--r-- 1 root root 3527 sep 15 20:01 build.xml
-rw-r--r-- 1 root root   82 sep 15 20:01 manifest.mf
drwxr-xr-x 3 root root 4096 sep 15 20:01 nbproject
drwxr-xr-x 3 root root 4096 sep 15 20:01 src

Root是每个文件的组和所有者的目录。

这导致当Netbeans生成文档文件时,它将“root”替换为我的用户名。

更新: 我只能以root身份启动neatbeans(sudo ./netbeans)。

当我没有sudo从终端运行neatbean时,它看起来像是在启动:屏幕截图

但随后它关闭了。

这是输出:

>Log Session: Sunday, September 16, 2018 at 12:58:20 PM Eastern Daylight Time
>System Info: 
  Product Version         = Apache NetBeans IDE 9.0 (Build incubator-netbeans-release-334-on-20180708)
  Operating System        = Linux version 4.15.0-34-generic running on amd64
  Java; VM; Vendor        = 10.0.1; Java HotSpot(TM) 64-Bit Server VM 10.0.1+10; Oracle Corporation
  Runtime                 = Java(TM) SE Runtime Environment 10.0.1+10
  Java Home               = /opt/java/jdk-10.0.1
  System Locale; Encoding = es_DO (nb); UTF-8
  Home Directory          = /home/star_man
  Current Directory       = /opt/netbeans
  User Directory          = /home/star_man/.netbeans/9.0
  Cache Directory         = /home/star_man/.cache/netbeans/9.0
  Installation            = /opt/netbeans/nb
                            /opt/netbeans/ide
                            /opt/netbeans/extide
                            /opt/netbeans/java
                            /opt/netbeans/apisupport
                            /opt/netbeans/websvccommon
                            /opt/netbeans/profiler
                            /opt/netbeans/harness
                            /opt/netbeans/javafx
                            /opt/netbeans/platform
  Boot & Ext. Classpath   = 
  Application Classpath   = /opt/netbeans/platform/lib/boot.jar:/opt/netbeans/platform/lib/org-openide-modules.jar:/opt/netbeans/platform/lib/org-openide-util.jar:/opt/netbeans/platform/lib/org-openide-util-lookup.jar:/opt/netbeans/platform/lib/org-openide-util-ui.jar
  Startup Classpath       = /opt/netbeans/platform/core/core-base.jar:/opt/netbeans/platform/core/org-netbeans-libs-asm.jar:/opt/netbeans/platform/core/asm-all-5.0.1.jar:/opt/netbeans/platform/core/org-openide-filesystems.jar:/opt/netbeans/platform/core/org-openide-filesystems-compat8.jar:/opt/netbeans/platform/core/core.jar:/opt/netbeans/nb/core/org-netbeans-upgrader.jar:/opt/netbeans/nb/core/locale/core_nb.jar
-------------------------------------------------------------------------------
INFO [org.netbeans.modules.netbinox]: Install area set to file:/opt/netbeans/
!SESSION 2018-09-16 12:58:21.698 -----------------------------------------------
eclipse.buildId=unknown
java.version=10.0.1
java.vendor=Oracle Corporation
BootLoader constants: OS=linux, ARCH=x86_64, WS=gtk, NL=es_DO

!ENTRY org.eclipse.osgi 4 0 2018-09-16 12:58:21.706
!MESSAGE Error reading configuration: Permission denied
!STACK 0
java.io.IOException: Permission denied
    at java.base/java.io.UnixFileSystem.createFileExclusively(Native Method)
    at java.base/java.io.File.createTempFile(File.java:2090)
    at org.eclipse.osgi.storagemanager.StorageManager.initializeInstanceFile(StorageManager.java:188)
    at org.eclipse.osgi.storagemanager.StorageManager.open(StorageManager.java:708)
    at org.eclipse.osgi.internal.baseadaptor.BaseStorage.initFileManager(BaseStorage.java:226)
    at org.eclipse.osgi.internal.baseadaptor.BaseStorage.initialize(BaseStorage.java:160)
    at org.eclipse.osgi.baseadaptor.BaseAdaptor.initializeStorage(BaseAdaptor.java:123)
    at org.eclipse.osgi.framework.internal.core.Framework.<init>(Framework.java:192)
    at org.eclipse.osgi.framework.internal.core.EquinoxLauncher.internalInit(EquinoxLauncher.java:67)
    at org.eclipse.osgi.framework.internal.core.EquinoxLauncher.init(EquinoxLauncher.java:37)
    at org.eclipse.osgi.launch.Equinox.init(Equinox.java:178)
    at org.netbeans.modules.netbinox.Netbinox.init(Netbinox.java:61)
    at org.netbeans.core.netigso.Netigso.prepare(Netigso.java:145)
    at org.netbeans.NetigsoHandle.turnOn(NetigsoHandle.java:115)
    at org.netbeans.ModuleManager.enable(ModuleManager.java:1331)
    at org.netbeans.ModuleManager.enable(ModuleManager.java:1148)
    at org.netbeans.core.startup.ModuleList.installNew(ModuleList.java:315)
    at org.netbeans.core.startup.ModuleList.trigger(ModuleList.java:251)
    at org.netbeans.core.startup.ModuleSystem.restore(ModuleSystem.java:276)
    at org.netbeans.core.startup.Main.getModuleSystem(Main.java:156)
    at org.netbeans.core.startup.Main.getModuleSystem(Main.java:125)
    at org.netbeans.core.startup.Main.start(Main.java:282)
    at org.netbeans.core.startup.TopThreadGroup.run(TopThreadGroup.java:98)
    at java.base/java.lang.Thread.run(Thread.java:844)
java.lang.RuntimeException: Permission denied
    at org.eclipse.osgi.framework.internal.core.Framework.<init>(Framework.java:194)
    at org.eclipse.osgi.framework.internal.core.EquinoxLauncher.internalInit(EquinoxLauncher.java:67)
    at org.eclipse.osgi.framework.internal.core.EquinoxLauncher.init(EquinoxLauncher.java:37)
    at org.eclipse.osgi.launch.Equinox.init(Equinox.java:178)
    at org.netbeans.modules.netbinox.Netbinox.init(Netbinox.java:61)
    at org.netbeans.core.netigso.Netigso.prepare(Netigso.java:145)
    at org.netbeans.NetigsoHandle.turnOn(NetigsoHandle.java:115)
    at org.netbeans.ModuleManager.enable(ModuleManager.java:1331)
    at org.netbeans.ModuleManager.enable(ModuleManager.java:1148)
    at org.netbeans.core.startup.ModuleList.installNew(ModuleList.java:315)
    at org.netbeans.core.startup.ModuleList.trigger(ModuleList.java:251)
    at org.netbeans.core.startup.ModuleSystem.restore(ModuleSystem.java:276)
    at org.netbeans.core.startup.Main.getModuleSystem(Main.java:156)
    at org.netbeans.core.startup.Main.getModuleSystem(Main.java:125)
    at org.netbeans.core.startup.Main.start(Main.java:282)
    at org.netbeans.core.startup.TopThreadGroup.run(TopThreadGroup.java:98)
    at java.base/java.lang.Thread.run(Thread.java:844)
Caused by: java.io.IOException: Permission denied
    at java.base/java.io.UnixFileSystem.createFileExclusively(Native Method)
    at java.base/java.io.File.createTempFile(File.java:2090)
    at org.eclipse.osgi.storagemanager.StorageManager.initializeInstanceFile(StorageManager.java:188)
    at org.eclipse.osgi.storagemanager.StorageManager.open(StorageManager.java:708)
    at org.eclipse.osgi.internal.baseadaptor.BaseStorage.initFileManager(BaseStorage.java:226)
    at org.eclipse.osgi.internal.baseadaptor.BaseStorage.initialize(BaseStorage.java:160)
    at org.eclipse.osgi.baseadaptor.BaseAdaptor.initializeStorage(BaseAdaptor.java:123)
    at org.eclipse.osgi.framework.internal.core.Framework.<init>(Framework.java:192)
    ... 16 more

我发现下面的每个文件和目录~/.netbeans都有root作为所有者和组。我认为这可能是问题所以我改变了所有者和组~/.netbeans $ sudo chown -R myusername: .netbeans/。而且我仍然只能以root身份运行netbeans。

提问于
用户回答回答于

这是一个基本的unix权限问题。

出于逃避我的原因,您曾经sudo启动过netbeansIDE。 - 你不应该那样做。 -你不应该需要做!

当您用于sudo运行某些内容时,通常以root用户身份运行。(那是什么sudo!)

因此,当然,某些东西(在这种情况下,netbeans运行的应用程序sudo)将创建“root”用户拥有的文件和目录。因此,当您尝试以普通用户身份更新它们时,操作系统会说“不:您不拥有这些文件/目录,因此您无法修改它们。”。

解决方案:使用该chown命令根据需要更改文件和目录的所有权。

怎么样?阅读man chown或查找有关如何更改文件所有权的教程。

  • 提示:你需要sudo在chowning时使用......
  • 提示2:使用时要非常非常小心sudo,因为sudo如果你犯了错误就有能力摧毁你的系统。

扫码关注云+社区

领取腾讯云代金券

年度创作总结 领取年终奖励