Code Review Videos > Linux > How To Disable smbd In Ubuntu

How To Disable smbd In Ubuntu

For reasons that currently escape me, I started using Docker for smbd a while back. I’m not sure if it’s the case by default, but my installation of Ubuntu has samba running as soon as the machine starts up.

This conflicts with the Docker container implementation, and as the local samba starts before Docker, that one wins and the actual share I want is then unavailable.

connect to ubuntu samba share from osx

How Can I Permanently Stop smbd From Starting When Rebooting?

To permanently stop the Samba service (smbd) from starting when rebooting in Ubuntu, you can use the systemctl command. Here are the steps you can follow:

  1. Open a terminal in Ubuntu.
  2. First, you need to disable the Samba service. You can do this using systemctl:
   sudo systemctl disable smbd

This command will prevent the Samba service from starting on boot.

Here’s my output:

➜  ~ sudo systemctl disable smbd
[sudo] password for chris: 
Synchronizing state of smbd.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install disable smbd
Removed "/etc/systemd/system/multi-user.target.wants/smbd.service".Code language: JavaScript (javascript)
  1. After disabling the service, it’s a good practice to stop it immediately with:
   sudo systemctl stop smbd

This will stop the service if it’s currently running. If successful, you won’t get any output from this one.

Hardcore Mode

You do not need to do this step.

To ensure that Samba won’t start on the next reboot, you can mask the service.

Masking a service creates a symbolic link from the service file to /dev/null, effectively preventing it from being started.

   sudo systemctl mask smbd

That’s it! Samba (smbd) should now be disabled and won’t start on reboot.

My Docker Samba Config

I’m sure at some point in the future I will want a reference to this, so I figured I would share it as part of this post.

This config file is based off the docker-compose.yaml file from the dperson/samba GitHub repo linked below.

Here’s the Docker config I use:

# docker-compose.yaml 

version: '3.4'

services:
  samba:
    image: dperson/samba
    networks:
      - default
    tmpfs:
      - /tmp
    restart: unless-stopped
    stdin_open: true
    tty: true
    ports:
      - 139:139
      - 445:445
    volumes:
      - "./share:/mnt/share1:rw"
    command: '-w workgroup -u "chris;chris" -s "silvershare;/mnt/share1;no;no;no;chris;chris"'

networks:
        default:Code language: PHP (php)

Here’s a break down of the key components of this docker-compose.yaml file:

# docker-compose.yaml

version: '3.4'Code language: PHP (php)
  • The version specifies the version of the Docker Compose file format that we are using. In this case, it’s ‘3.4’.
services:
  samba:
    image: dperson/samba
  • Under the services section, a service named ‘samba’ is defined. This service is based on the ‘dperson/samba’ Docker image.
    networks:
      - default
    tmpfs:
      - /tmpCode language: JavaScript (javascript)
  • The networks section specifies that the ‘samba’ service is connected to the ‘default’ network.
  • tmpfs is used to create a temporary file system in the ‘/tmp’ directory for this container.

Any data written to /tmp in the container will be stored in memory and will not be persisted to my host machine’s local disk.

tmpfs will only work on Linux host systems as far as I am aware.

    restart: unless-stopped
    stdin_open: true
    tty: trueCode language: JavaScript (javascript)
  • restart: unless-stopped means that the container will automatically restart unless it is explicitly stopped.
  • stdin_open: true and tty: true indicate that the container is configured to keep standard input open and allocate a pseudo-TTY. Useful for debugging but I rarely need to interact directly with the samba service.
    ports:
      - 139:139
      - 445:445Code language: CSS (css)
  • The ports section maps ports from the host to the container. In this case, port 139 and 445 on the host are mapped to the same ports on the ‘samba’ container.

These two lines are essential for connectivity to the share.

    volumes:
      - "./share:/mnt/share1:rw"Code language: JavaScript (javascript)
  • volumes are used to mount directories from the host to the container. In this case, the ‘./share’ directory on my computer is mounted as ‘/mnt/share1’ in the container, and it’s mounted with read and write permissions (‘rw’).

Basically this means that in the same directory that I have my docker-compose.yaml file, I also have a share directory which is where any / all shared files actually live on my computer. This persists beyond the lifecycle of the container – so if the container is stopped or deleted, the data isn’t lost / removed.

    command: '-w workgroup -u "chris;chris" -s "silvershare;/mnt/share1;no;no;no;chris;chris"'Code language: JavaScript (javascript)
  • The command section specifies the command that will be run when the container starts.

This command configures a Samba share named “silvershare” with the workgroup “workgroup,” using the user “chris” with the password “chris” for access.

Highly secure. But it’s for local transfer between two machines and I’m comfortable with the risks.

The share is associated with the directory “/mnt/share1” in the container, and any optional samba share settings are explicitly disabled with the no;no;no part.

networks:
  default:Code language: JavaScript (javascript)
  • Lastly, the ‘networks’ section defines the ‘default’ network that is used in this Compose file.

This Docker Compose file is used to create and configure a Samba container that shares the ‘/mnt/share1’ directory with certain settings. You can use the docker-compose command to start this service with the specified configuration.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.