如何获得将文件从一个文件夹复制到另一个文件夹的权限?

如何获得将文件从一个文件夹复制到另一个文件夹的权限?

因此,我尝试使用该cp命令将一些文件从一个文件夹复制到另一个文件夹,但是在尝试时它给了我这个错误:

debian@OCR-1:/mnt/rootfs/boot$ ls
MLO             omap3-overo-storm-arbor43c.dtb  uEnv.txt  zImage-3.18-20150915
initrd-ubi.img  u-boot.img   zImage
debian@OCR-1:~$ cp /mnt/rootfs/boot/MLO /var/log/MLO
cp: can't create '/var/log/MLO': Permission denied

所以然后我尝试执行相同的命令,sudo但它也不起作用:

debian@OCR-1:~$ sudo cp /mnt/rootfs/boot/MLO /var/log/MLO
-bash: sudo: command not found

在我尝试查看每个文件夹的权限后:

debian@OCR-1:/var$ ls -l
total 5
drwxr-xr-x  9 root root 4096 May 16  2018 archive
drwxr-xr-x  4 root root    0 Jan  1 00:00 lib
drwxrwxr-x  2 root root    0 Jan  1 00:56 lock
drwxr-xr-x 11 root root 1024 Jan  1 00:00 log
drwxrwxr-x  4 root root    0 Jan  1 00:01 run
drwxrwxr-x  3 root root    0 Jan  1 00:00 spool
drwxr-xr-x  3 root root    0 Jan  1 00:00 www

debian@OCR-1:/mnt/rootfs/boot$ ls -l
total 11160
-rwxr-xr-x 1 root root   59148 Jan 24  2014 MLO
-rwxr-xr-x 1 root root 1220219 Jan  1 00:16 initrd-ubi.img
-rwxr-xr-x 1 root root   69463 Jan 24  2014 omap3-overo-storm-arbor43c.dtb
-rwxr-xr-x 1 root root  470632 Jan 24  2014 u-boot.img
-rwxr-xr-x 1 root root    2038 Jan  1 00:16 uEnv.txt
-rwxr-xr-x 1 root root 4798000 Jan  1 00:20 zImage
-rwxr-xr-x 1 root root 4798000 Jan 24  2014 zImage-3.18-20150915

但后来我不知道下一步该做什么,因为我不知道如何理解数据。有人可以帮我解决这个问题吗?

[编辑]

所以我试图看看我是否有 root 访问权限,但它向我展示了这一点:

debian@OCR-1:~$ id
uid=1000(debian) gid=1002(debian) groups=4(adm),20(dialout),24(cdrom),25(floppy),29(audio),30(dip),44(video),46(plugdev),100(users),106(netdev),108(i2c),1000(admin),1001(spi),1002(debian)
debian@OCR-1:~$ whoami
debian
debian@OCR-1:~$ su -
su: must be suid to work properly

然后我尝试安装sudo,但不能:

debian@OCR-1:~$ apt update && apt install -y sudo
-bash: apt: command not found

答案1

为了能够sudo在debian上使用,首先需要安装并配置它。


安装sudo

首先您需要登录您的根帐户。

然后运行以下命令来安装该sudo软件包:

apt update && apt install -y sudo

配置sudo

如果安装完成且没有错误,您可以配置sudo为允许您的用户升级权限。 Debian 通常默认配置为允许 sudo 组中的用户通过 sudo 运行命令。您可以在仍然登录 root 帐户的情况下运行visudo并查找以下行来检查这一点:

# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL

#如果前面有 ,%sudo请将其删除,以便该行看起来与上面完全相同。请务必小心,不要弄乱该文件,因为它可能会使您的系统无法使用!


将您的用户添加到 sudo 组:

如果该行存在,您可以将普通用户(在您的情况下)添加debian到 sudo 组。你可以这样做usermod

usermod -aG sudo debian

where-aG表示“附加到组”

-a, --append
           Add the user to the supplementary group(s). Use only with the -G option.

-G, --groups GROUP1[,GROUP2,...[,GROUPN]]]
           A list of supplementary groups which the user is also a member of. Each group is separated from the next by a comma, with no intervening whitespace. The groups are subject to the same
           restrictions as the group given with the -g option.

           If the user is currently a member of a group which is not listed, the user will be removed from the group. This behaviour can be changed via the -a option, which appends the user to the current
           supplementary group list.

现在注销 root 帐户并登录到您的 debian 用户帐户。您现在应该能够通过 root 身份运行命令sudo

笔记:该目录/var/log/通常仅用于自动生成的日志文件。

相关内容