Kali Linux Setup Samba Share for Home LAN: Difference between revisions

From WikiMLT
m (Text replacement - "mlw-continue" to "code-continue")
 
Line 2: Line 2:


== Install Samba ==
== Install Samba ==
<syntaxhighlight lang="shell" line="1" class="mlw-continue">
<syntaxhighlight lang="shell" line="1" class="code-continue">
sudo apt install samba smbclient nautilus-share
sudo apt install samba smbclient nautilus-share
</syntaxhighlight><syntaxhighlight lang="shell" line="1" class="mlw-continue mlw-shell-gray">
</syntaxhighlight><syntaxhighlight lang="shell" line="1" class="code-continue mlw-shell-gray">
sudo usermod -aG sambashare $USER  
sudo usermod -aG sambashare $USER  
</syntaxhighlight>
</syntaxhighlight>


== Samba Basic Setup ==
== Samba Basic Setup ==
Add or modify the following lines within <code>smb.conf</code>.<syntaxhighlight lang="shell" line="1" class="mlw-continue">
Add or modify the following lines within <code>smb.conf</code>.<syntaxhighlight lang="shell" line="1" class="code-continue">
sudo nano /etc/samba/smb.conf
sudo nano /etc/samba/smb.conf
</syntaxhighlight><syntaxhighlight lang="shell" line="1" class="mlw-continue mlw-shell-gray">
</syntaxhighlight><syntaxhighlight lang="shell" line="1" class="code-continue mlw-shell-gray">
cat /etc/samba/smb.conf | grep -Pv '^(;|\s*#)' | sed '/^$/d'
cat /etc/samba/smb.conf | grep -Pv '^(;|\s*#)' | sed '/^$/d'
</syntaxhighlight><syntaxhighlight lang="terraform" class="mlw-pre-max-height-320" highlight="2-5,17,18" line="1">
</syntaxhighlight><syntaxhighlight lang="terraform" class="mlw-pre-max-height-320" highlight="2-5,17,18" line="1">
Line 58: Line 58:
* The following is not listed default value from the <code>[global]</code> section: <code>usershare path = /var&shy;/&shy;lib&shy;/&shy;samba&shy;/&shy;user&shy;shares</code>.
* The following is not listed default value from the <code>[global]</code> section: <code>usershare path = /var&shy;/&shy;lib&shy;/&shy;samba&shy;/&shy;user&shy;shares</code>.


Restart the Samba and the NetBIOS services.<syntaxhighlight lang="shell" line="1" class="mlw-continue">
Restart the Samba and the NetBIOS services.<syntaxhighlight lang="shell" line="1" class="code-continue">
sudo systemctl restart smbd.service nmbd.service
sudo systemctl restart smbd.service nmbd.service
</syntaxhighlight>
</syntaxhighlight>


== Share a Directory via CLI ==
== Share a Directory via CLI ==
'''1.''' One option is to edit the file <code>smb.conf</code> and add a section, as the shown below, at the very bottom of the file. Then restart the Samba and the NetBIOS services.<syntaxhighlight lang="shell" line="1" class="mlw-continue">
'''1.''' One option is to edit the file <code>smb.conf</code> and add a section, as the shown below, at the very bottom of the file. Then restart the Samba and the NetBIOS services.<syntaxhighlight lang="shell" line="1" class="code-continue">
sudo nano /etc/samba/smb.conf
sudo nano /etc/samba/smb.conf
</syntaxhighlight><syntaxhighlight lang="terraform" class="mlw-pre-max-height-320"  line="1" start="40">
</syntaxhighlight><syntaxhighlight lang="terraform" class="mlw-pre-max-height-320"  line="1" start="40">
Line 76: Line 76:
* The section name <code>[Share]</code> is matter of you choice - this will become the name of the shared folder.
* The section name <code>[Share]</code> is matter of you choice - this will become the name of the shared folder.
* The directory provided as <code>path</code> value, <code>/home/share</code> in this case, must have enough permissions.
* The directory provided as <code>path</code> value, <code>/home/share</code> in this case, must have enough permissions.
'''2.''' Another option is to use the <code>[https://manpages.ubuntu.com/manpages/jammy/en/man8/net.8.html net usershare]</code> tool in a way as the the following to create or remove a network share.<syntaxhighlight lang="shell" line="1" class="mlw-continue">
'''2.''' Another option is to use the <code>[https://manpages.ubuntu.com/manpages/jammy/en/man8/net.8.html net usershare]</code> tool in a way as the the following to create or remove a network share.<syntaxhighlight lang="shell" line="1" class="code-continue">
net usershare add Git /home/$USER/Git "$USER's git projects" Everyone:F guest_ok=y
net usershare add Git /home/$USER/Git "$USER's git projects" Everyone:F guest_ok=y
</syntaxhighlight><syntaxhighlight lang="shell" line="1" class="mlw-continue mlw-shell-gray">
</syntaxhighlight><syntaxhighlight lang="shell" line="1" class="code-continue mlw-shell-gray">
net usershare delete Git
net usershare delete Git
</syntaxhighlight>The above command will share the user's <code>~/Git</code> directory and will grant it guest access. The command actually creates a file entry in <code>/var&shy;/&shy;lib&shy;/&shy;samba&shy;/&shy;user&shy;shares</code>.<syntaxhighlight lang="shell" line="1" class="mlw-continue">
</syntaxhighlight>The above command will share the user's <code>~/Git</code> directory and will grant it guest access. The command actually creates a file entry in <code>/var&shy;/&shy;lib&shy;/&shy;samba&shy;/&shy;user&shy;shares</code>.<syntaxhighlight lang="shell" line="1" class="code-continue">
cat /var/lib/samba/usershares/git
cat /var/lib/samba/usershares/git
</syntaxhighlight><syntaxhighlight lang="terraform" class="mlw-pre-max-height-320" line="1" start="1">
</syntaxhighlight><syntaxhighlight lang="terraform" class="mlw-pre-max-height-320" line="1" start="1">
Line 100: Line 100:
It is much comfortable to share directories via the context menu (right mouse button) within the Nautilus file explorer. Unfortunately, in Kali Linux 2022, the package <code>nautilus-share</code> suffers from a known bug that causes the following error message: <code>''"net usershare" has returned error 255...''</code>
It is much comfortable to share directories via the context menu (right mouse button) within the Nautilus file explorer. Unfortunately, in Kali Linux 2022, the package <code>nautilus-share</code> suffers from a known bug that causes the following error message: <code>''"net usershare" has returned error 255...''</code>


This bug is fixed within some other distributions and as workaround we can use the <code>libnautilus-share.so</code> file from the [https://launchpad.net/ubuntu/+source/nautilus-share Ubuntu 22.04's package]. <syntaxhighlight lang="shell" line="1" class="mlw-continue">
This bug is fixed within some other distributions and as workaround we can use the <code>libnautilus-share.so</code> file from the [https://launchpad.net/ubuntu/+source/nautilus-share Ubuntu 22.04's package]. <syntaxhighlight lang="shell" line="1" class="code-continue">
cd /tmp
cd /tmp
wget https://launchpad.net/ubuntu/+archive/primary/+files/nautilus-share_0.7.3-2ubuntu6_amd64.deb
wget https://launchpad.net/ubuntu/+archive/primary/+files/nautilus-share_0.7.3-2ubuntu6_amd64.deb
Line 106: Line 106:
tar --strip-components=6 -xvf "data.tar.zst" \
tar --strip-components=6 -xvf "data.tar.zst" \
./usr/lib/x86_64-linux-gnu/nautilus/extensions-3.0/libnautilus-share.so
./usr/lib/x86_64-linux-gnu/nautilus/extensions-3.0/libnautilus-share.so
</syntaxhighlight><syntaxhighlight lang="shell" line="1" class="mlw-continue mlw-shell-gray">
</syntaxhighlight><syntaxhighlight lang="shell" line="1" class="code-continue mlw-shell-gray">
sudo mv /usr/lib/x86_64-linux-gnu/nautilus/extensions-3.0/libnautilus-share.so{,.default}
sudo mv /usr/lib/x86_64-linux-gnu/nautilus/extensions-3.0/libnautilus-share.so{,.default}
</syntaxhighlight><syntaxhighlight lang="shell" line="1" class="mlw-continue">
</syntaxhighlight><syntaxhighlight lang="shell" line="1" class="code-continue">
sudo mv libnautilus-share.so /usr/lib/x86_64-linux-gnu/nautilus/extensions-3.0/
sudo mv libnautilus-share.so /usr/lib/x86_64-linux-gnu/nautilus/extensions-3.0/
sudo chown root:root /usr/lib/x86_64-linux-gnu/nautilus/extensions-3.0/libnautilus-share.so
sudo chown root:root /usr/lib/x86_64-linux-gnu/nautilus/extensions-3.0/libnautilus-share.so
</syntaxhighlight><syntaxhighlight lang="shell" line="1" class="mlw-continue mlw-shell-gray">
</syntaxhighlight><syntaxhighlight lang="shell" line="1" class="code-continue mlw-shell-gray">
pkill -9 nautilus
pkill -9 nautilus
</syntaxhighlight>After restarting Nautilus you will see at {{Media-cite|sf|1}} position {{Pti|s=1|i=A|c=green}} after applying the above steps the label in the Nautilus' context menu is changed from ''Sharing Options'' to ''Local Network Share''. Now everything should work fine.  
</syntaxhighlight>After restarting Nautilus you will see at {{Media-cite|sf|1}} position {{Pti|s=1|i=A|c=green}} after applying the above steps the label in the Nautilus' context menu is changed from ''Sharing Options'' to ''Local Network Share''. Now everything should work fine.  

Latest revision as of 08:29, 26 September 2022

In­stall Sam­ba

sudo apt install samba smbclient nautilus-share
sudo usermod -aG sambashare $USER

Sam­ba Ba­sic Set­up

Add or mod­i­fy the fol­low­ing lines with­in smb.conf.

sudo nano /etc/samba/smb.conf
cat /etc/samba/smb.conf | grep -Pv '^(;|\s*#)' | sed '/^$/d'
[global]
   client min protocol = LANMAN1
   server min protocol = LANMAN1
   workgroup = WORKGROUP
   interfaces = 127.0.0.0/8 eth0 br0
   log file = /var/log/samba/log.%m
   max log size = 1000
   logging = file
   panic action = /usr/share/samba/panic-action %d
   server role = standalone server
   obey pam restrictions = yes
   unix password sync = yes
   passwd program = /usr/bin/passwd %u
   passwd chat = *Enter\snew\s*\spassword:* %n\n *Retype\snew\s*\spassword:* %n\n *password\supdated\ssuccessfully* .
   pam password change = yes
   map to guest = bad user
   usershare allow guests = yes
   usershare owner only = false
[homes]
   comment = Home Directories
   browseable = no
   read only = yes
   create mask = 0700
   directory mask = 0700
   valid users = %S
[printers]
   comment = All Printers
   browseable = no
   path = /var/spool/samba
   printable = yes
   guest ok = no
   read only = yes
   create mask = 0700
[print$]
   comment = Printer Drivers
   path = /var/lib/samba/printers
   browseable = yes
   read only = yes
   guest ok = no

Notes:

  • For client/​​​server min pro­to­col you can try al­so with NT1 or SMB2.
  • The fol­low­ing is not list­ed de­fault val­ue from the [glob­al] sec­tion: user­share path = /​​​var­/​​​­lib­/​​​­samba­/​​​­user­shares.

Restart the Sam­ba and the Net­BIOS ser­vices.

sudo systemctl restart smbd.service nmbd.service

Share a Di­rec­to­ry via CLI

1. One op­tion is to ed­it the file smb.conf and add a sec­tion, as the shown be­low, at the very bot­tom of the file. Then restart the Sam­ba and the Net­BIOS ser­vices.

sudo nano /etc/samba/smb.conf
[Share]
   comment = Shared filews
   path = /home/share
   public = yes
   writable = yes

Notes:

  • The sec­tion name [Share] is mat­ter of you choice – this will be­come the name of the shared fold­er.
  • The di­rec­to­ry pro­vid­ed as path val­ue, /​​​home/​​​share in this case, must have enough per­mis­sions.

2. An­oth­er op­tion is to use the net user­share tool in a way as the the fol­low­ing to cre­ate or re­move a net­work share.

net usershare add Git /home/$USER/Git "$USER's git projects" Everyone:F guest_ok=y
net usershare delete Git

The above com­mand will share the user's ~/​​​Git di­rec­to­ry and will grant it guest ac­cess. The com­mand ac­tu­al­ly cre­ates a file en­try in /​​​var­/​​​­lib­/​​​­samba­/​​​­user­shares.

cat /var/lib/samba/usershares/git
#VERSION 2
path=/home/<user>/Git
comment=<user>'s git projects
usershare_acl=S-1-1-0:F
guest_ok=y
sharename=Git

Notes:

  • man net/​​​usershare: The op­tion­al "acl" field spec­i­fies which users have read and write ac­cess to the en­tire share. Note that guest con­nec­tions are not al­lowed un­less the smb.conf pa­ra­me­ter "user­share al­low guests" has been set. The de­f­i­n­i­tion of a user de­fined share acl is: "user:permission", where user is a valid user­name on the sys­tem and per­mis­sion can be "F", "R", or "D".
    • "F" stands for "full per­mis­sions", ie. read and write per­mis­sions.
    • "D" stands for "de­ny" for a user, ie. pre­vent this user from ac­cess­ing this share.
    • "R" stands for "read on­ly", ie. on­ly al­low read ac­cess to this share (no cre­ation of new files or di­rec­to­ries or writ­ing to files).
  • In ad­di­tion the user must have enough filesys­tem per­mis­sions to the di­rec­to­ry, for ex­am­ple yf you re­al­ly want to al­low every­one to write to the di­rec­to­ry you may need to chmod o+rwx ~/​​​Git.

Share a Di­rec­to­ry via Nau­tilus

It is much com­fort­able to share di­rec­to­ries via the con­text menu (right mouse but­ton) with­in the Nau­tilus file ex­plor­er. Un­for­tu­nate­ly, in Kali Lin­ux 2022, the pack­age nau­tilus-share suf­fers from a known bug that caus­es the fol­low­ing er­ror mes­sage: "net user­share" has re­turned er­ror 255…

This bug is fixed with­in some oth­er dis­tri­b­u­tions and as workaround we can use the libnautilus​-share​.so file from the Ubun­tu 22.04's pack­age.

cd /tmp
wget https://launchpad.net/ubuntu/+archive/primary/+files/nautilus-share_0.7.3-2ubuntu6_amd64.deb
ar x "nautilus-share_0.7.3-2ubuntu6_amd64.deb" "data.tar.zst"
tar --strip-components=6 -xvf "data.tar.zst" \
./usr/lib/x86_64-linux-gnu/nautilus/extensions-3.0/libnautilus-share.so
sudo mv /usr/lib/x86_64-linux-gnu/nautilus/extensions-3.0/libnautilus-share.so{,.default}
sudo mv libnautilus-share.so /usr/lib/x86_64-linux-gnu/nautilus/extensions-3.0/
sudo chown root:root /usr/lib/x86_64-linux-gnu/nautilus/extensions-3.0/libnautilus-share.so
pkill -9 nautilus

Af­ter restart­ing Nau­tilus you will see at Screen 1 po­si­tion A af­ter ap­ply­ing the above steps the la­bel in the Nau­tilus' con­text menu is changed from Shar­ing Op­tions to Lo­cal Net­work Share. Now every­thing should work fine.

Screen 1. Kali Lin­ux 2022: the re­plac­ing of libnautilus​-share​.so, in or­der to fix the bug "net user­share" has re­turned er­ror 255, caus­es a change of the la­bel in the Nau­tilus' con­text menu. Screen 1. Kali Linux 2022: the replacing of libnautilus-share.so, in order to fix the bug "net usershare" has returned error 255, causes a change of the label in the Nautilus' context menu.

Ref­er­ences

Gen­er­al Sam­ba Refs

Nau­tilus Trou­bleshoot­ing
De­bian pack­ages ma­nip­u­la­tion