我们可以创建名称中有空格的用户主目录吗?像 /test 123

1 linux user-management

我需要将 /data/test 123 之类的路径映射为用户 testuser 的主目录,但它不接受主目录路径中的空间?

它不允许我使用usermod -m -d /new path username.

use*_*517 5

您可以使用-d切换到 useradd

useradd -d '/home/test 123' test123
Run Code Online (Sandbox Code Playgroud)

添加单引号'也适用于 usermod 但请注意,这会破坏各种不需要空格的东西,例如

su - test123
-bash: [: /home/test: binary operator expected
Run Code Online (Sandbox Code Playgroud)

同样,如果您使用未经测试的东西,例如 tst 123

su - test123
-bash: [: /home/tst: binary operator expected
Run Code Online (Sandbox Code Playgroud)

为自己省去很多痛苦,不要那样做。