coiai Logo

This article is an English translation of the original Japanese post. Read the Japanese original →

Completely Removing and Reinstalling Samba on Ubuntu

November 7, 2024

Categories: Linux · Tags: NAS, Samba, Ubuntu, サーバー

About This Post

Samba is the go-to tool for running Ubuntu as a file server.

If you reinstall it after some kind of glitch, there are cases where the samba directory and smb.conf under /etc don't get created.

This post covers a reliable way to fully remove it — dependencies included — for cases like that.

Completely Removing Samba

First, stop the Samba that's currently running.

service smbd stop
service nmbd stop

Use the purge command to fully remove Samba. If you don't use purge, some config files and directories will stick around, and smb.conf may not get created the next time you install it.

sudo apt remove --purge samba samba-common
sudo apt autoremove

Remove any config files or directories still left at this point.
⚠️ If you want to back up your config files, do that first.

sudo rm -rf /etc/samba /var/lib/samba

Reinstalling

Install it again.

sudo apt update
sudo apt install samba

Let's check that it went through properly.

ls /etc/samba

Confirming It Works

Configure smb.conf using Vi.

sudo vi /etc/samba/smb.conf

Add the following to the end of smb.conf. With this setup, every user will be able to access it.

[TEST]
path = 共有したいディレクトリのパス
public = yes
security = share
writable = yes
printable = no
guest ok = yes

And that's the whole process.