我一直在尝试在 Ubuntu 20.04lts 下的 Linux PC 上安装 LAMP 设置。
我是主要的 sudo 用户,在尝试保存 nano 文件并在 /var/www/html 文件夹中创建目录时,我不断收到“权限被拒绝”消息。
计算机位置的文件中的所有文件夹的权限都呈灰色。我猜这意味着我无法添加或修改这些文件的内容。
我已经安装了 Apache2、MariahDB 和 PHP,但无法创建或修改任何 INI 文件。
有时我会收到一条消息,说我没有访问权限,因为我不是 root 用户。我认为作为拥有所有管理员权限的主要 Sudo 用户,我应该是实际的 Root 用户并拥有所有访问权限。
我究竟做错了什么?
谢谢
答案1
如果您想以用户身份执行一系列命令root
而不必sudo
每次都在每个命令前加上前缀,我建议使用sudo -i
以用户身份获取登录 shell root
。摘自手册:
-i, --login
Run the shell specified by the target user's password database entry as a login
shell. This means that login-specific resource files such as .profile,
.bash_profile or .login will be read by the shell. If a command is specified,
it is passed to the shell for execution via the shell's -c option. If no
command is specified, an interactive shell is executed. sudo attempts to change
to that user's home directory before running the shell. The command is run with
an environment similar to the one a user would receive at log in. Note that
most shells behave differently when a command is specified as compared to an
interactive session; consult the shell's manual for details. The Command
environment section in the sudoers(5) manual documents how the -i option affects
the environment in which a command is run when the sudoers policy is in use.
或者,如果您记得在设置过程中设置了 root 密码(这在 Ubuntu Server 的情况下不太可能——该root
帐户通常被禁用),您可以root
使用该su root
命令将用户更改为。