Samba: Difference between revisions

From 太極
Jump to navigation Jump to search
No edit summary
Line 79: Line 79:
* [http://www.unixmen.com/howto-install-and-configure-samba-share-in-ubuntu/ Share between ubuntu and linux] On the client file manager, type '''smb://192.168.1.XX/'''
* [http://www.unixmen.com/howto-install-and-configure-samba-share-in-ubuntu/ Share between ubuntu and linux] On the client file manager, type '''smb://192.168.1.XX/'''
* https://help.ubuntu.com/community/Samba
* https://help.ubuntu.com/community/Samba
<ul>
<li>(2020-04-27) Ubuntu 18.04. This is following the class "Building an Ubuntu Home Server" in lynda.com</li>
  <ol>
  <li>mkdir /mnt/stored/shared </li>
  <li>chmod 444 /mnt/storage/shared </li>
  <li>sudo apt install samba </li>
  <li>sudo nano /etc/samba/smb.conf. Scroll down to the bottom and add </li>
<pre>
[fileshare]
  comment = share files
  path = /mnt/storage/shared
  readonly = yes
  create mask = 0444
  directory mask = 0444
</pre>
  <li>testparm </li>
  <li>sudo systemctl restart smbd </li>
  <li>sudo smbpasswd -a CurrUserName </li>
  <li>sudo useradd user2 </li>
  <li>sudo passwd user2 </li>
  <li>sudo smbpasswd -a user2 </li>
  <li>sudo ufw allow 139/tcp </li>
  <li>sudo ufw allow 445/tcp </li>
  </ol>
</ul>


On Windows PC, go to start and open 'Run' then enter ip with double backslash. Like this (\\192.168.1.XX).
On Windows PC, go to start and open 'Run' then enter ip with double backslash. Like this (\\192.168.1.XX). On macOS/Linux, "Connect to Server" in the file browser, smb://192.168.1.XX/fileshare.


== Raspberry pi ==
== Raspberry pi ==

Revision as of 20:43, 27 April 2020

Samba - allows Linux to transfer files with Windows clients

sudo apt-get install -y samba samba-common python-glade2 system-config-samba
sudo cp -pf /etc/samba/smb.conf /etc/samba/smb.conf.bak
sudo sh -c 'cat /dev/null  > /etc/samba/smb.conf'
sudo nano /etc/samba/smb.conf
sudo service smbd restart
testparm
# password protected
sudo addgroup smbgrp
sudo useradd till -G smbgrp
sudo smbpasswd -a SOMEEXISTEDUSER
sudo mkdir -p /samba/secured
cd /samba
sudo chmod -R 0770 secured
sudo chown root:smbgrp secured
sudo nano /etc/samba/smb.conf
sudo service smbd restart 
testparm

sudo netstat -pant | grep smbd   # mine shows 139 & 445
  • I have trouble to connect to the samba server though connecting it itself from the samba server works fine.
$ smbclient -L //192.168.1.XX/sambashare -U SOMEEXISTEDUSER
WARNING: The "syslog" option is deprecated
Connection to 192.168.1.XX failed (Error NT_STATUS_IO_TIMEOUT)

# From server itself
$ smbclient -L //localhost 

# Solution: ufw
# https://askubuntu.com/a/184806
sudo ufw allow Samba

# From the client 
$ smbclient -L //192.168.1.XX/sambashare -U YYY
# No error. Return to the local prompt again.
# Now we can use Ubuntu's Files app to connect to the server
# smb://192.168.1.XX/
$ ps -ef | grep smbd    # see if the Samba daemon (smbd)
$ ps -ef | grep nmbd    # see if the NetBIOS name server daemon (nmbd) is running

$ sudo service smbd stop  # does not stop nmbd 
$ sudo service nmbd stop

$ sudo service smbd start
$ sudo service nmbd start
sudo apt-get install samba samba-common
sudo apt-get install python-glade2
sudo apt-get install system-config-samba

Use Dash and search for 'samba'. It will ask for the user's password first. The samba password can also be set by

sudo smbpasswd -a USERNAME

A non-gui way to configuration samba is adding the following to the end of /etc/samba/smb.conf file, sudo nano -w /etc/samba/smb.conf (-w means no-wrap). Any line beginning with a semicolon (“;”) or a hash (“#”) character is ignored.

[brb]
        path = /home/brb
;       writeable = no
;       browseable = yes
        guest ok = yes
  • (2020-04-27) Ubuntu 18.04. This is following the class "Building an Ubuntu Home Server" in lynda.com
    1. mkdir /mnt/stored/shared
    2. chmod 444 /mnt/storage/shared
    3. sudo apt install samba
    4. sudo nano /etc/samba/smb.conf. Scroll down to the bottom and add
    5. [fileshare]
        comment = share files
        path = /mnt/storage/shared
        readonly = yes
        create mask = 0444
        directory mask = 0444
      
    6. testparm
    7. sudo systemctl restart smbd
    8. sudo smbpasswd -a CurrUserName
    9. sudo useradd user2
    10. sudo passwd user2
    11. sudo smbpasswd -a user2
    12. sudo ufw allow 139/tcp
    13. sudo ufw allow 445/tcp

On Windows PC, go to start and open 'Run' then enter ip with double backslash. Like this (\\192.168.1.XX). On macOS/Linux, "Connect to Server" in the file browser, smb://192.168.1.XX/fileshare.

Raspberry pi

Build your own NAS drive with Raspberry Pi

Remove and re-install Samba

$ sudo apt-get remove --purge samba
$ sudo apt-get remove --purge smbclient libsmbclient

$ sudo apt-get install samba
$ sudo apt-get install smbclient libsmbclient

SambaCry vulnerability and check Samba version

http://pcworld.com/article/3199106/linux/the-sambacry-scare-gives-linux-users-a-taste-of-wannacry-petya-problems.html

To check your samba version

$ smbd -V
Version 4.3.11-Ubuntu

Mounting a Samba Share using the cifs-utils package

Mounting a Samba Share

Example of /etc/samba/smb.conf

[global]
workgroup = WORKGROUP
server string = Samba Server %v
netbios name = ubuntu
security = user
map to guest = bad user
dns proxy = no
logging = syslog@0 file
unix extensions = no

[share]
follow symlinks = yes
wide links = yes

[sambashare]
comment = Samba on Ubuntu
path = /Path1/
read only = no
writable = yes
browsable = yes
guest ok = no

[taichiVideo]
comment = tai chi video
path = /Path2/
read only = yes
writable = no
browsable = yes
guest ok = yes