Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save 1eedaegon/bc367c45670530f71e29b98a9408d3bd to your computer and use it in GitHub Desktop.

Select an option

Save 1eedaegon/bc367c45670530f71e29b98a9408d3bd to your computer and use it in GitHub Desktop.
How to share an NTFS directory from Windows 11 Pro to Ubuntu via SMB

On Windows Server

  • Make shared folder
  • Allow logged in user
# 1. Open PowerSell > Run as Administrator 

# 2. Create a shared directory 
New-Item -Path "C:\shared-smb-ntfs" -ItemType Directory -Force

# 3. SMB: Allow all logged-in users(-FullAccess "Everyone")
New-SmbShare -Name "shared-smb-ntfs" -Path "C:\shared-smb-ntfs" -FullAccess "Everyone" 

# 4. NTFS: Allow Folder Access all logged-in users (/grant Everyone:F)
# NTFS: Recursively (/T)
icacls "C:\shared-smb-ntfs" /grant Everyone:F /T

# 5. Firewall Rule and Group(EN)
Enable-NetFirewallRule -DisplayGroup "File and Printer Sharing (SMB-Out)"

# 5. Firewall Rule and Group(KR)
# Enable-NetFirewallRule -DisplayGroup "파일  프린터 공유"

# 6. Check SMB Sharing
Get-SmbShare

On Ubuntu Server

  • Mount smb directory
  • Configure systemd to automatically mount on reboot
# 1. Make mount directory
$ mkdir -p /data

# 2. Create credentials for SMB users (using both systemd and scripts)
$ vi /etc/systemd/system/samba-credentials
username=some_user
password=some_pass

# 3. Make shell
$ vi [Some PATH]/mount-smb.sh

#!/bin/bash
# USER has 1000:1000
mount -t cifs //[Windows Server Address]/shared-smb-ntfs /data \n
-o credentials=/etc/systemd/system/samba-credentials,uid=1000,gid=1000

# 5. mount
$ chmod +x [Some path]/mount-smb.sh
$ [Some path]/mount-smb.sh

# 6. check mount successful
$ df -h
...
//[Window Server Address]/shared-smb-ntfs   931G  454G  477G  49% /data

# 7. regiser auto mount
$ vi /etc/systemd/system/mount-smb.service

# USER has 1000:1000
[Unit]
Description=Mount SMB Share
After=network-online.target
Wants=network-online.target

[Service]
Type=oneshot
RemainAfterExit=yes
USER=1000
GROUP=1000
ExecStart=/usr/bin/sudo /[SomePath]/mount-smb.sh
ExecStop=/usr/bin/sudo /bin/umount /data

[Install]
WantedBy=multi-user.target

# 8. �Enable systemd:  Good luck! now finished
systemctl enable mount-smb.service

# NOTICE: When systemctl start mount-smb.service, 
# the `mount-smb.service` will fail since the share is already mounted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment