[英]Root doesn‘t have the permission to change a directory owner
I can't change a directory's owner even if I'm root.即使我是 root,我也无法更改目录的所有者。
I want to build a NAS by using raspberry 3B+.我想用raspberry 3B+搭建一个NAS。
Maybe its best to remove the user and try again, this is what I did to make it work.也许最好删除用户并重试,这就是我为使其工作所做的工作。
pi
user, only default logins exist.以pi
用户身份登录新设置的 raspberry pi,仅存在默认登录名。pi@raspberrypi:~ $ whoami
pi
pi@raspberrypi:~ $ lslogins -u
UID USER PROC PWD-LOCK PWD-DENY LAST-LOGIN GECOS
0 root 84 root
1000 pi 5 15:31 ,,,
dorm
添加新用户dorm
$ sudo adduser dorm
Adding user `dorm' ...
Adding new group `dorm' (1001) ...
Adding new user `dorm' (1001) with group `dorm' ...
Creating home directory `/home/dorm' ...
Copying files from `/etc/skel' ...
New password:
Retype new password:
passwd: password updated successfully
Changing the user information for dorm
Enter the new value, or press ENTER for the default
Full Name []:
Room Number []:
Work Phone []:
Home Phone []:
Other []:
Is the information correct? [Y/n] y
pi@raspberrypi:~ $ lslogins -u
UID USER PROC PWD-LOCK PWD-DENY LAST-LOGIN GECOS
0 root 87 root
1000 pi 5 15:31 ,,,
1001 dorm 0 ,,,
sshd_config
file,备份并编辑您的sshd_config
文件,pi@raspberrypi:~ $ sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config-bak
pi@raspberrypi:~ $ sudo vim /etc/ssh/sshd_config
pi@raspberrypi:~ $ diff /etc/ssh/sshd_config /etc/ssh/sshd_config-bak
122,128d121
<
< Match User dorm
< X11Forwarding no
< AllowTcpForwarding no
< PermitTTY no
< ForceCommand internal-sftp
< ChrootDirectory /home/dorm
sudo service sshd restart
使用sudo service sshd restart
启动 ssh 服务$ sudo chown root:root /home/dorm
$ sudo chmod 755 /home/dorm
dorm
user从 dorm 用户的目录使用 sudo 作为 pi 用户创建 Documents 文件夹并将所有权授予dorm
用户pi@raspberrypi:/home/dorm $ ls
pi@raspberrypi:/home/dorm $ mkdir Documents
mkdir: cannot create directory ‘Documents’: Permission denied
pi@raspberrypi:/home/dorm $ sudo mkdir Documents
pi@raspberrypi:/home/dorm $ ls -l
total 4
drwxr-xr-x 2 root root 4096 Feb 8 18:15 Documents
pi@raspberrypi:/home/dorm $ sudo chown -R dorm:dorm Documents
pi@raspberrypi:/home/dorm $ ls -l
total 4
drwxr-xr-x 2 dorm dorm 4096 Feb 8 18:15 Documents
No route to host
)使用主机上的 IP 地址测试连接等(ssh 应回复No route to host
)$ sftp dorm@<IP>
dorm@<IP>'s password:
Connected to dorm@<IP>.
sftp>
sftp> ls -ltr
drwxr-xr-x 2 1001 1001 4096 Feb 8 18:15 Documents
sftp> pwd
Remote working directory: /
sftp> cd ..
sftp> pwd
Remote working directory: /
sftp> put /Users/<USER>/tmp
Uploading /Users/<USER>/tmp to /tmp
remote open("/tmp"): Permission denied
Documents
then you can then upload files如果你进入Documents
那么你可以上传文件sftp> cd Documents
sftp> put /Users/<USER>/tmp
Uploading /Users/<USER>/tmp to /Documents/tmp
/Users/<USER>/tmp 100% 0 0.0KB/s 00:00
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.