Unable to change with invalid mode: 'usr1:usr1' error in wsl2 in chmod usr1:usr1 file

Asked 1 years ago, Updated 1 years ago, 333 views

I want to change the file owner and group of root:root to usr1.

If you run sudo chmod usr1:usr1file to change the username and group name on wsl2, you cannot change it with the chmod:invalid mode:'usr1:usr1' error.

Install by wsl--install-d Ubuntu with PowerShell administrator privileges.

PSC:\Users\admin>wsl-l-v
  NAME STATE VERSION
* Ubuntu Running 2

Operation at Ubuntu terminal

:
Enter new UNIX username—usr1
:
usr1@pc:~$ sudo su-
root@pc:~#cd../home/usr1
root@pc:/home/usr1#echoabc>file
root@pc:/home/usr1#exit

usr1@pc:~$ls-l
-rw -r --r -- 1 root root 4 Dec 421:49 file

usr1@pc:~$sudo chmod777file
usr1@pc:~$ls-l
- rwxrwxrwx1 root root4 Dec 421:49 file

usr1@pc:~$sudo chmod usr1:usr1 file
chmod: invalid mode: 'usr1:usr1'
Try'chmod --help' for more information

The symptom is the same no matter how many times you uninstall and reinstall Ubuntu.
I think there is a wrong operation.
Thank you for pointing it out.

Windows 10 Pro 22H2 Windows 11 Home 22H2 ※ Both symptoms are the same.

ubuntu windows-10 wsl-2

2022-12-04 18:10

1 Answers

To change the file owner, use the chown command.
(chmod is the command to change permission=permission of the file.)

Name

chown - Change the owner and group of files

Format

chown [OPTION]...[OWNER][:[GROUP] FILE...


2022-12-04 21:15

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.