Ubuntu 22.04 での Samba の使い方です。
ソフトのインストール
sudo apt install samba
sudo apt install smbclient
バージョンの確認
$ samba -V
Version 4.15.9-Ubuntu
$ smbclient -V
Version 4.15.9-Ubuntu
Samba でアクセスするフォルダーの作成
mkdir /var/tmp/json
mkdir /var/tmp/plain_text
設定ファイルの修正
/etc/samba/smb.conf
(省略)
#
[json]
comment = json
path = /var/tmp/json
browseable = yes
read only = no
guest ok = yes
#
[plain_text]
comment = Plain Text
path = /var/tmp/plain_text
browseable = yes
read only = no
guest ok = yes
#
サーバーの再起動
sudo systemctl restart smbd
sudo systemctl restart nmbd
クライアントで共有名を調べる
$ smbclient -L localhost -U uchida%password
Sharename Type Comment
--------- ---- -------
print$ Disk Printer Drivers
json Disk json
plain_text Disk Plain Text
IPC$ IPC IPC Service (iwata server (Samba, Ubuntu))
SMB1 disabled -- no workgroup available
共有名 json にアクセス
$ smbclient //localhost/json -U uchida%password
Try "help" to get a list of possible commands.
smb: \> ls
. D 0 Wed Aug 3 14:35:02 2022
.. D 0 Sun Sep 18 13:39:04 2022
code_cities.json N 3095 Sat Apr 4 12:19:20 2020
tochigi.json N 405 Sun Aug 7 19:53:58 2022
cities.json N 944 Wed Aug 3 14:41:21 2022
102687672 blocks of size 1024. 34773172 blocks available
smb: \> exit
共有名 plain_text にアクセス
$ smbclient //localhost/plain_text -U uchida%password
Try "help" to get a list of possible commands.
smb: \> ls
. D 0 Fri Apr 24 11:00:46 2020
.. D 0 Sun Sep 18 13:39:04 2022
cities.txt N 267 Wed Jan 26 09:44:06 2022
102687672 blocks of size 1024. 34773056 blocks available
smb: \> exit
設定ファイルを、
[json]
comment = json
path = /var/tmp/json
browseable = yes
read only = no
guest ok = no
とすると、
$ smbclient //localhost/json -U uchida%password
tree connect failed: NT_STATUS_ACCESS_DENIED
となります。
解決するには、
$ sudo smbpasswd -a uchida
New SMB password:
Retype new SMB password:
Added user uchida.
Samba のパスワードファイルに登録されているユーザーの確認
$ sudo pdbedit -L
uchida:1200:uchida