Samba API
Samba
References:
- Ubuntu - What is Samba?
- Ubuntu Samba
- Install and configure Samba
- Accessing an SMB Share With Linux Machines
- man smbclient
- Client Access - Browsing SMB shares
- How to Create a Network Share Via Samba Via CLI
Services
Show samba config
/v1/?action=list-shares
Example
http://localhost:8080/v1/?action=list-shares:
{
"global": {
"workgroup": "GROUP",
"security": "user"
}
}
Command
smbclient:
$ cat /etc/samba/smb.conf
[global]
workgroup = GROUP
security = user
Add shared folder
/v1/?action=add-share§ion=:section&user=:user&path=:path&validUsers=:validUsers&comment=:comment
Params
Name | Type | Description |
---|---|---|
:section | String | section |
:user | String | user |
:path | String | path |
:validUsers | String | validUsers |
:comment | String | comment |
Example
{
"status": "add shared successfully"
}
Command
smbserver:
$ mkdir /home/vagrant/shared
$ sudo smbpasswd -a vagrant
New SMB password:
Retype new SMB password:
Added user vagrant.
$ cat << EOF | sudo tee --append /etc/samba/smb.conf
[vagrant]
comment = public folder of vagrant
writeable = yes
path = /home/vagrant/shared
browseable = yes
valid users = vagrant
EOF
# sudo service smbd restart
# sudo service nmbd restart
$ testparm
Load smb config files from /etc/samba/smb.conf
rlimit_max: increasing rlimit_max (1024) to minimum Windows limit (16384)
Processing section "[vagrant]"
Loaded services file OK.
Server role: ROLE_STANDALONE
Press enter to see a dump of your service definitions
# Global parameters
[global]
workgroup = GROUP
security = USER
idmap config * : backend = tdb
[vagrant]
comment = public folder of vagrant
path = /home/vagrant/shared
valid users = vagrant
read only = No
$ cat /etc/samba/smb.conf
[global]
workgroup = GROUP
security = user
[vagrant]
comment = public folder of vagrant
path = /home/vagrant/shared
valid users = vagrant
writeable = yes
browseable = yes
smbclient:
$ smbclient //192.168.1.2/vagrant -U vagrant%vagrant
WARNING: The "syslog" option is deprecated
Domain=[GROUP] OS=[Windows 6.1] Server=[Samba 4.3.11-Ubuntu]
smb: \> pwd
Current directory is \\192.168.1.2\vagrant\
smb: \> ls
. D 0 Thu Jul 12 03:00:54 2018
.. D 0 Thu Jul 12 03:00:54 2018
41251136 blocks of size 1024. 37763796 blocks available
smb: \> mkdir test
smb: \> ls
. D 0 Thu Jul 12 03:10:32 2018
.. D 0 Thu Jul 12 03:00:54 2018
test D 0 Thu Jul 12 03:10:32 2018
41251136 blocks of size 1024. 37763792 blocks available
Remove shared folder
/v1/?action=add-share§ion=:section
Params
Name | Type | Description |
---|---|---|
:section | String | section name |
Example
http://localhost:8080/v1/?action=rm-share§ion=vagrant:
{
"status": "remove shared successfully"
}
Command
smbserver:
$ mkdir /home/vagrant/shared
$ ?? delete
# sudo service smbd restart
# sudo service nmbd restart
$ cat /etc/samba/smb.conf
[global]
workgroup = GROUP
security = user
smbclient:
$ smbclient -L 192.168.1.2
??