Aller au contenu

Samba#

References#

https://ubuntu.com/tutorials/install-and-configure-samba#3-setting-up-samba https://wiki.samba.org/index.php/User_Documentation https://serverfault.com/questions/630631/how-to-make-samba-share-to-not-ask-for-password

Installation & Configuration#

Install#

Bash
apt install -y samba

Configure Samba Server in Standalone mode#

Config Ref: https://www.samba.org/samba/docs/current/man-html/smb.conf.5.html

Bash
mkdir -p $DATA_DIR

# Create Samba user
SAMBA_USER=myuser
SAMBA_PASS=mypassword
useradd -d $DATA_DIR $SAMBA_USER -s /sbin/nologin
echo -ne "$SAMBA_PASS\n$SAMBA_PASS\n" | smbpasswd -a -s $SAMBA_USER

cp /etc/samba/smb.conf /etc/samba/smb.conf.bak
samba_conf_file=$(cat <<EOF

[global]
    server role = standalone server
    bind interfaces only = No
    disable netbios = Yes
    smb ports = 445
    log file = /var/log/samba/smb.log
    max log size = 10000

[data]
    comment = Data files
    path = $DATA_DIR
    read only = no
    public = yes
    browsable = yes
    guest ok = yes
    guest only = yes
    force create mode = 0660
    force directory mode = 2770
    force user = myuser
    force group = myuser

EOF
)
echo "$samba_conf_file" > /etc/samba/smb.conf

Restart Server#

Bash
1
2
3
4
5
systemctl restart smbd
systemctl status smbd

# List Samba Users
pdbedit -L -v
  • Install Samba client : apt install smbclient
Bash
1
2
3
4
smbclient -U /myuser //10.77.0.230/shared
smbclient //10.77.0.230/shared

smbclient -U WORKGROUP/myuser //10.77.0.230/shared

Server Commands#

  • Add Linux User : useradd -M $SAMBA_USER -s /sbin/nologin
  • Add samba user: echo -ne "$SAMBA_PASS\n$SAMBA_PASS\n" | smbpasswd -a -s $SAMBA_USER
  • Change domain to a User: pdbedit -u $SAMBA_USER -I $WORKGROUP
  • List samba users: pdbedit -L -v