NFS Server : Simple user mapping to Linux2024/12/06 |
If you want to set simple user mapping when using NFS between Windows and Linux in a non-Active Directory domain environment, configure as follows. |
|
[1] | Check the user/group information on the Linux side. |
root@dlp:~# cat /etc/passwd ..... ..... ubuntu:x:1000:1000:ubuntu:/home/ubuntu:/bin/bash debian:x:1001:1001:,,,:/home/debian:/bin/bash redhat:x:1002:1002:,,,:/home/redhat:/bin/bash root@dlp:~# cat /etc/group ..... ..... users:x:100:debian,redhat ubuntu:x:1000: debian:x:1001: redhat:x:1002: |
[2] | On the Windows side, create a file for simple mapping. |
Windows PowerShell Copyright (C) Microsoft Corporation. All rights reserved. PS C:\Users\Serverworld> New-Item C:\Windows\System32\drivers\etc\passwd Directory: C:\Windows\System32\drivers\etc Mode LastWriteTime Length Name ---- ------------- ------ ---- -a---- 12/5/2024 8:23 PM 0 passwd PS C:\Users\Serverworld> New-Item C:\Windows\System32\drivers\etc\group Directory: C:\Windows\System32\drivers\etc Mode LastWriteTime Length Name ---- ------------- ------ ---- -a---- 12/5/2024 8:23 PM 0 group # for example, map user winuser01 ⇔ debian PS C:\Users\Serverworld> Add-Content C:\Windows\System32\drivers\etc\passwd ` "winuser01:x:1001:1001:debian::" # for example, map user winuser02 ⇔ redhat PS C:\Users\Serverworld> Add-Content C:\Windows\System32\drivers\etc\passwd ` "winuser02:x:1002:1002:redhat::" # for example, map group BUILTIN\Users ⇔ users PS C:\Users\Serverworld> Add-Content C:\Windows\System32\drivers\etc\group ` "BUILTIN\Users:x:100:users" # for example, map group BUILTIN\Users ⇔ debian PS C:\Users\Serverworld> Add-Content C:\Windows\System32\drivers\etc\group ` "BUILTIN\Users:x:1001:debian" # for example, map group BUILTIN\Users ⇔ redhat PS C:\Users\Serverworld> Add-Content C:\Windows\System32\drivers\etc\group ` "BUILTIN\Users:x:1002:redhat" |
[3] | Set the access permission so that each user can access the folder. |
# for Windows NFS servers, grant read and execute permissions to Everyone on the root folder of the NFS share PS C:\Users\Serverworld> icacls C:\nfsshare01 /grant "Everyone:(NP)(RX)" processed file: C:\nfsshare01 Successfully processed 1 files; Failed processing 0 files # whether the NFS server is Windows or Linux, create a dedicated folder that each user can access in advance # Windows NFS server # * winuser01 ⇔ debian can access PS C:\Users\Serverworld> mkdir C:\nfsshare01\winuser01 PS C:\Users\Serverworld> icacls C:\nfsshare01\winuser01 /setowner winuser01 processed file: C:\nfsshare01\winuser01 Successfully processed 1 files; Failed processing 0 files # Linux NFS server # * winuser02 ⇔ redhat can access root@dlp:~# mkdir /home/nfsshare/redhat root@dlp:~# chown redhat:redhat /home/nfsshare/redhat |
[4] | Log in to the Linux client as the configured user and check the mapping to the Windows NFS server. |
root@dlp:~# mount -t nfs 10.0.0.101:/nfsshare01 /mnt root@dlp:~# su - debian debian@dlp:~$ ll /mnt total 5 drwxr-xr-x 2 4294967294 4294967294 64 Dec 6 06:07 ./ drwxr-xr-x 23 root root 4096 Apr 26 2024 ../ drwx------ 2 debian 4294967294 64 Dec 6 06:07 winuser01/ debian@dlp:~$ echo test > /mnt/winuser01/testfile.txt debian@dlp:~$ ll /mnt/winuser01 total 2 drwx------ 2 debian 4294967294 64 Dec 6 06:08 ./ drwxr-xr-x 2 4294967294 4294967294 64 Dec 6 06:07 ../ -rw-rw-r-- 1 debian debian 5 Dec 6 06:08 testfile.txt |
[5] | Sign in to a Windows client with the configured user and check the mapping to the Linux NFS server. |
PS C:\Users\winuser02> mount.exe 10.0.0.30:/home/nfsshare Z:\ PS C:\Users\winuser02> Get-ChildItem Z:\ Directory: Z:\ Mode LastWriteTime Length Name ---- ------------- ------ ---- d----- 12/5/2024 9:51 PM redhat PS C:\Users\winuser02> Add-Content Z:\redhat\testfile.txt "test file" PS C:\Users\winuser02> Get-ChildItem Z:\redhat Directory: Z:\redhat Mode LastWriteTime Length Name ---- ------------- ------ ---- -a---- 12/5/2024 10:10 PM 11 testfile.txt PS C:\Users\winuser02> ssh redhat@10.0.0.30 "ls -l /home/nfsshare/redhat" redhat@10.0.0.30's password: total 4 -rw-r--r-- 1 redhat redhat 11 Dec 6 06:10 testfile.txt |
Sponsored Link |
|