Programster's Blog

Tutorials focusing on Linux, programming, and open-source

Samba Cheatsheet

Table Of Contents

  1. Related Posts
  2. User Management
    1. List Users
    2. Add Users
    3. Set User Password
  3. Configuration
    1. Add Another Share
    2. Logging
  4. Checking Status
    1. List Shares / Services Available To User
    2. LIst Current Connections
  5. References

User Management

List Users

sudo pdbedit --list --verbose

... or for more detailed information

sudo pdbedit --list --verbose | less

Add Users

This is the "samba way" to add SAMBA users (and definitely the way to use if you are using SAMBA for active directory).

samba-tool user create myUserName

However, I have been using the following in the past to create linux users don't have a home directory and can't login with SSH, which works with how I set up SAMBA for file sharing.

sudo useradd \
  --no-create-home  \
  --shell /usr/sbin/nologin  \

You should see the user like so in the /etc/passwd file:


Set User Password

Then set a password for the user for the first time:

sudo smbpasswd -a $USERNAME

I had an issue when configuring Proxmox to use a SAMBA share when I had special characters in the password, so I would recommend using a long alphanumeric password.


Samba Service

Restart Samba Service

sudo service smbd start

You don't have to restart the service after creating a user and setting their password. It should immediately take effect.


Add Another Share

Add a section like below to the /etc/samba/smb.conf file. Obviously tweak the values as necessary.

  comment = Read only share except for authorized users
  path = /mydata/mystuff/
  public = no
  guest ok = no
  read only = yes
  create mask = 0644
  directory mask = 0755
  force group = mygroup
  write list = myname, @mygroup


Refer to my Samba Logging tutorial.

Checking Status

List Shares / Services Available To User

smbclient --list $SAMBA_HOST --user $SAMBA_USER

This will ask you for your user's password before listing the shares/services available to you. Below is some example output:

    Sharename       Type      Comment
    ---------       ----      -------
    docker-volumes  Disk      Docker volumes
    print$          Disk      Printer Drivers
    IPC$            IPC       IPC Service (Samba 4.17.8-Debian)
SMB1 disabled -- no workgroup available

List Current Connections

If you want to see who is currently connected and to what, you can use the following command:

sudo smbstatus

If you are only interested in people being connected to the shared, you can do:

sudo smbstatus --shares


Last updated: 9th July 2023
First published: 24th June 2019