Kali Linux Setup Samba Share for Home LAN: Difference between revisions
m (→Notes:) |
m (Text replacement - "mlw-continue" to "code-continue") |
||
(26 intermediate revisions by the same user not shown) | |||
Line 2: | Line 2: | ||
== Install Samba == | == Install Samba == | ||
<syntaxhighlight lang="shell" line="1" class=" | <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=" | </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=" | 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=" | </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­/­lib­/­samba­/­user­shares</code>. | * The following is not listed default value from the <code>[global]</code> section: <code>usershare path = /var­/­lib­/­samba­/­user­shares</code>. | ||
Restart the Samba and the NetBIOS services.<syntaxhighlight lang="shell" line="1" class=" | 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=" | '''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]</code> tool in a way as the the following to create or remove a network share.<syntaxhighlight lang="shell" line="1" class=" | '''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=" | </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­/­lib­/­samba­/­user­shares</code>.<syntaxhighlight lang="shell" line="1" class=" | </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­/­lib­/­samba­/­user­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 96: | Line 96: | ||
** "R" stands for "read only", ie. only allow read access to this share (no creation of new files or directories or writing to files). | ** "R" stands for "read only", ie. only allow read access to this share (no creation of new files or directories or writing to files). | ||
* In addition the user must have enough filesystem permissions to the directory, for example yf you really want to allow everyone to write to the directory you may need to <code>chmod o+rwx ~/Git</code>. | * In addition the user must have enough filesystem permissions to the directory, for example yf you really want to allow everyone to write to the directory you may need to <code>chmod o+rwx ~/Git</code>. | ||
== Share a Directory via Nautilus == | |||
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="code-continue"> | |||
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 | |||
</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} | |||
</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 chown root:root /usr/lib/x86_64-linux-gnu/nautilus/extensions-3.0/libnautilus-share.so | |||
</syntaxhighlight><syntaxhighlight lang="shell" line="1" class="code-continue mlw-shell-gray"> | |||
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. | |||
{{sform|1|Kali-linux--libnautilus-share.so--change.png | |||
| m = {{pt|s=1|i=A|c=green|a=270|x=726|y=350|z=1}} | |||
| s = 0.9 | |||
| t = 16 | |||
| side = 16 | |||
}} | |||
== References == | == References == | ||
* ... | === General Samba Refs === | ||
* SAMBA: [https://www.samba.org/samba/docs/ Documentation] | [https://wiki.samba.org/index.php/Main_Page '''Wiki'''] | |||
* Linux Hint: [https://linuxhint.com/install_samba_ubuntu/ How to Install Samba on Ubuntu] | |||
* Kali Linux Docs: [https://www.kali.org/docs/general-use/samba-configuration/ Samba Configuration] | |||
* DigitalOcean: [https://www.digitalocean.com/community/tutorials/how-to-set-up-a-samba-share-for-a-small-organization-on-ubuntu-16-04 How To Set Up a Samba Share For A Small Organization on Ubuntu 16.04] | |||
* Red Hat Blog: [https://www.redhat.com/sysadmin/samba-file-sharing How to share files with Samba] | |||
* Red Hat Blog: [https://www.redhat.com/sysadmin/samba-windows-linux Mounting and mapping shares between Windows and Linux with Samba] | |||
* Raspberry Pi SE: [https://raspberrypi.stackexchange.com/q/84565/59699 Samba - How to Disable LAN Samba Server Discovery] | |||
===== Nautilus Troubleshooting ===== | |||
* '''I should report the issue on: [https://bugs.kali.org/view_all_bug_page.php?refresh=true Kali Linux Bug Tracker]''' | |||
* Manjaro GitLab: [https://gitlab.manjaro.org/packages/community/xfce/thunar-shares-plugin/-/issues/1 <nowiki>Please update this package, it is outdated and broken [Calling "net usershare" created error 255]</nowiki>] | |||
* Manjaro Support: [https://forum.manjaro.org/t/cant-share-directory-through-nautilus/87517 Can’t share directory through nautilus] | [https://forum.manjaro.org/t/thunar-shares-plugin-net-usershare-error-255/93591 Thunar Shares Plugin ‘net usershare’ error 255] | |||
* Ubuntu Mate Support: [https://ubuntu-mate.community/t/net-usershare-has-returned-error-255/25667 “net usershare” has returned error 255] | |||
* Ubuntu Mate Support: [https://ubuntu-mate.community/t/sharing-public-folders-between-computers-over-the-network/25431 Sharing Public folders between computers over the network] | |||
* Ask Ubuntu: [https://askubuntu.com/questions/798928/nautilus-share-message-called-net-usershare-info-but-it-failed Nautilus-Share-Message: Called "net usershare info" but it failed] | |||
===== Debian packages manipulation ===== | |||
* Ubuntu on Launchpad: [https://launchpad.net/ubuntu/+source/nautilus-share Nautilus-share package in Ubuntu] | |||
*Ask Ubuntu: [https://askubuntu.com/a/30581/566421 Is there an apt command to download a deb file from the repositories to the current directory?] | |||
*FAQforge.com: [https://www.faqforge.com/linux/how-to-download-and-extract-a-deb-package-on-ubuntu-or-debian-linux/ '''How to download and extract a .deb package on Ubuntu or Debian Linux'''] | |||
*LinuxConfig.org: [https://linuxconfig.org/how-to-extract-file-from-debian-package-archive-deb '''How to extract files from Debian package archive DEB'''] | |||
*NixCraft: [https://www.cyberciti.biz/faq/linux-unix-extracting-specific-files/ Tar Extract a Single File(s) From a Large Tarball] | |||
*Stack Overflow: [https://stackoverflow.com/a/845601/6543935 '''How do I untar a subdirectory into the current directory?'''] | |||
*Unix and Linux: [https://unix.stackexchange.com/q/61461/201297 How to extract specific file(s) from tar.gz] | |||
<noinclude> | <noinclude> | ||
<div id='devStage'> | <div id='devStage'> | ||
{{devStage | {{devStage | ||
| Прндл = Linux Desktop | | Прндл = Linux Desktop | ||
| Стадий = | | Стадий = 6 | ||
| Фаза = | | Фаза = Утвърждаване | ||
| Статус = | | Статус = Утвърден | ||
| ИдтПт = Spas | | ИдтПт = Spas | ||
| РзбПт = {{REVISIONUSER}} | | РзбПт = Spas | ||
| АвтПт = Spas | |||
| УтвПт = {{REVISIONUSER}} | |||
| ИдтДт = 14.09.2022 | | ИдтДт = 14.09.2022 | ||
| РзбДт = {{Today}} | | РзбДт = 14.09.2022 | ||
| АвтДт = 14.09.2022 | |||
| УтвДт = {{Today}} | |||
| ИдтРв = [[Special:Permalink/31489|31489]] | | ИдтРв = [[Special:Permalink/31489|31489]] | ||
| РзбРв = {{REVISIONID}} | | РзбРв = [[Special:Permalink/31533|31533]] | ||
| АвтРв = [[Special:Permalink/31535|31535]] | |||
| УтвРв = {{REVISIONID}} | |||
}} | }} | ||
</div> | </div> | ||
</noinclude> | </noinclude> |
Latest revision as of 07:29, 26 September 2022
Install Samba
sudo apt install samba smbclient nautilus-share
sudo usermod -aG sambashare $USER
Samba Basic Setup
Add or modify the following lines within 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 protocol you can try also with
NT1
orSMB2
. - The following is not listed default value from the
[global]
section:usershare path = /var/lib/samba/usershares
.
Restart the Samba and the NetBIOS services.
sudo systemctl restart smbd.service nmbd.service
1. One option is to edit the file smb.conf
and add a section, as the shown below, at the very bottom of the file. Then restart the Samba and the NetBIOS services.
sudo nano /etc/samba/smb.conf
[Share]
comment = Shared filews
path = /home/share
public = yes
writable = yes
Notes:
- The section name
[Share]
is matter of you choice – this will become the name of the shared folder. - The directory provided as
path
value,/home/share
in this case, must have enough permissions.
2. Another option is to use the net usershare
tool in a way as the the following to create or remove a network share.
net usershare add Git /home/$USER/Git "$USER's git projects" Everyone:F guest_ok=y
net usershare delete Git
The above command will share the user's ~/Git
directory and will grant it guest access. The command actually creates a file entry in /var/lib/samba/usershares
.
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 optional "acl" field specifies which users have read and write access to the entire share. Note that guest connections are not allowed unless the smb.conf parameter "usershare allow guests" has been set. The definition of a user defined share acl is: "user:permission", where user is a valid username on the system and permission can be "F", "R", or "D".- "F" stands for "full permissions", ie. read and write permissions.
- "D" stands for "deny" for a user, ie. prevent this user from accessing this share.
- "R" stands for "read only", ie. only allow read access to this share (no creation of new files or directories or writing to files).
- In addition the user must have enough filesystem permissions to the directory, for example yf you really want to allow everyone to write to the directory you may need to
chmod o+rwx ~/Git
.
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 nautilus-share
suffers from a known bug that causes the following error message: "net usershare" has returned error 255…
This bug is fixed within some other distributions and as workaround we can use the libnautilus-share.so
file from the Ubuntu 22.04's package.
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
After restarting Nautilus you will see at Screen 1 position A 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.
References
General Samba Refs
- SAMBA: Documentation | Wiki
- Linux Hint: How to Install Samba on Ubuntu
- Kali Linux Docs: Samba Configuration
- DigitalOcean: How To Set Up a Samba Share For A Small Organization on Ubuntu 16.04
- Red Hat Blog: How to share files with Samba
- Red Hat Blog: Mounting and mapping shares between Windows and Linux with Samba
- Raspberry Pi SE: Samba – How to Disable LAN Samba Server Discovery
Nautilus Troubleshooting
- I should report the issue on: Kali Linux Bug Tracker
- Manjaro GitLab: Please update this package, it is outdated and broken [Calling "net usershare" created error 255]
- Manjaro Support: Can’t share directory through nautilus | Thunar Shares Plugin ‘net usershare’ error 255
- Ubuntu Mate Support: “net usershare” has returned error 255
- Ubuntu Mate Support: Sharing Public folders between computers over the network
- Ask Ubuntu: Nautilus-Share-Message: Called "net usershare info" but it failed
Debian packages manipulation
- Ubuntu on Launchpad: Nautilus-share package in Ubuntu
- Ask Ubuntu: Is there an apt command to download a deb file from the repositories to the current directory?
- FAQforge.com: How to download and extract a .deb package on Ubuntu or Debian Linux
- LinuxConfig.org: How to extract files from Debian package archive DEB
- NixCraft: Tar Extract a Single File(s) From a Large Tarball
- Stack Overflow: How do I untar a subdirectory into the current directory?
- Unix and Linux: How to extract specific file(s) from tar.gz