Running a Samba Server on Jetson platforms
|
About Samba
Samba is the standard Windows interoperability suite of programs for Linux and Unix. It turns out to be an interesting option to share files and scripts between devices over a network. Some advantages provided could be that:
- It provides file sharing and print services for computers on a network.
- It uses the Server Message Block and Common Internet File System (SMB/CIFS) protocol.
- Samba can be available on Linux, macOS, and Windows clients.
- It is an easy, flexible, cross-platform, and open source collaboration approach across an organization.
- It is platform agnostic (as it was mentioned, it can run in several operated systems).
- It can run on terminal or using a GUI.
This wiki explains:
- How to install Samba on Ubuntu
- How to configure it as a standalone server to provide file sharing between a Jetson and a local PC, over a network.
- How to use the Samba client
- How to mount a Samba server on a local PC directory.
- How to connect to a Samba server using a Samba client.
The implementation and steps provided on this wiki were tested on a Jetson Xavier AGX running JetPack 5.0.2 and 5.1.
Prerequisites
Update the apt packages index:
sudo apt update
Install the Samba package:
sudo apt install samba
After that, the Samba service will start automatically. Check whether the Samba server is running:
sudo systemctl status smbd
Getting started
Configuring Global Samba Options
Create a backup of the smb.conf file, this could help to get back to the default settings in the future:
sudo cp /etc/samba/smb.conf{,.backup}
Open the file and make sure that the server role is set to "standalone server":
sudo vim /etc/samba/smb.conf
... # Most people will want "standalone sever" or "member server". # Running as "active directory domain controller" will require first # running "samba-tool domain provision" to wipe databases and create a # new domain. server role = standalone server ...
Restart the Samba services with:
sudo systemctl restart smbd sudo systemctl restart nmbd
Creating Samba Users and Directory Structure
Samba directories and its data can be located everywhere across the filesystem. For this case, directory structure will be located under the /samba path. Using the /samba directory instead of using the standard home directories (/home/$USER) allows easier maintainability and flexibility.
Create the /samba directory:
sudo mkdir /samba
Set the group ownership to "sambashare". This group is created during the Samba installation.
sudo chgrp sambashare /samba
Creating Samba Users
This section helps to create a regular user that has its private file share and one administrative account with read and write access to all shares on the Samba server.
To create a new user named "ridgerun", use the following command:
sudo useradd -M -d /samba/ridgerun -s /usr/sbin/nologin -G sambashare ridgerun
The useradd options have the following meanings:
- M: -do not create the user’s home directory.
- d: /samba/ridgerun - set the user’s home directory to /samba/ridgerun.
- s: /usr/sbin/nologin - disable shell access for this user.
- G: sambashare - add the user to the sambashare group.
Create the user’s home directory and set the directory ownership to user ridgerun and group sambashare:
sudo mkdir /samba/ridgerun sudo chown ridgerun:sambashare /samba/ridgerun
Set the directory’s permissions to 2770, this allows the sadmin user(a group that will be created later during this wiki) to create a new file that the user "ridgerun" will be able to read/write.
sudo chmod 2770 /samba/ridgerun
Add the "ridgerun" user account to the Samba database by setting the user password:
sudo smbpasswd -a ridgerun
Samba uses Linux users and group permission system but is has its own authentication mechanism separate from the standard Linux authentication. You will be prompted to enter and confirm the user password:
New SMB password: Retype new SMB password: Added user ridgerun.
Enable the Samba account run:
sudo smbpasswd -e ridgerun
Output
Enabled user ridgerun.
Change permissions on the Samba shared file:
sudo chmod 2770 /samba/ridgerun
To create another user repeat the same process as was shown before.
Create an user and group sadmin
All members of this group, sadmin, will have administrative permissions. Later if you want to grant administrative permissions to another user simply add that user to the sadmin group.
Create the administrative user:
sudo useradd -M -d /samba/users -s /usr/sbin/nologin -G sambashare sadmin
This creates a group sadmin and add the user "users" to both sadmin and sambashare groups.
Set a password and enable the user:
sudo smbpasswd -a sadmin sudo smbpasswd -e sadmin
Create the Users share directory:
sudo mkdir /samba/users
Set the directory ownership to user sadmin and group sambashare:
sudo chown sadmin:sambashare /samba/users
This directory will be accessible by all authenticated users. The following chmod command gives write/read access to members of the sambashare group in the /samba/users directory:
sudo chmod 2770 /samba/users
The /etc/samba/smb.conf file allows to edit the configuration of the samba sharefolders, by adding them as below:
+[users] + path = /samba/users + browseable = yes + read only = no + force create mode = 0660 + force directory mode = 2770 + valid users = @sambashare @sadmin +[ridgerun] + path = /samba/ridgerun + browseable = no + read only = no + force create mode = 0660 + force directory mode = 2770 + valid users = ridgerun @sadmin
- [users] and [ridgerun]: The names of the share users that you will use when logging in.
- path: The path to the share directory.
- browseable: Whether the share should be listed in the available shares list. By configuring it as "no" other users will not be able to see the share.
- read only: Whether the users specified in the valid users list are able to write to this share.
- force create mode: Sets the permissions for the newly created files in this share.
- force directory mode: Sets the permissions for the newly created directories in this share.
- valid users: A list of users and groups that are allowed to access the share.
Groups are prefixed with the "@" symbol.. |
Once the configuration file is ready, restart the Samba services with:
sudo systemctl restart smbd sudo systemctl restart nmbd
Access the samba share from the command line, using the file manager or mount the Samba share can be done. This section explains how to access to a sharefolder using smbclient client.
smbclient is a tool that allows you to access Samba from the command line. It is a package that is not pre-installed on most Linux distributions, so it must be installed using distribution package managers.
To install smbclient on Ubuntu and Debian, run:
sudo apt install smbclient
The syntax to access a Samba share is:
smbclient //samba_hostname_or_server_ip/share_name -U username
For example to connect to a share named ridgerun, on a Samba server with IP address 192.168.121.118, as user ridgerun, then the appropriate command to do that will be:
smbclient //192.168.121.118/ridgerun -U ridgerun
A password output will be prompted. Enter the password assigned before:
Enter WORKGROUP\ridgerun's password:
Once the password is entered, you will be logged into the Samba command line interface.
Try "help" to get a list of possible commands. smb: \>
This approach helps to move files from the sambashare folder to the local system, edit them and add them back.
Install the cifs-utils package. On Ubuntu and Debian, run:
sudo apt install cifs-utils
Next, create a mount point:
sudo mkdir /mnt/smbmount
Mount the share using the following command:
sudo mount -t cifs -o username=username //samba_hostname_or_server_ip/sharename /mnt/smbmount
For instance:
sudo mount -t cifs -o username=ridgerun //192.168.121.118/ridgerun /mnt/smbmount
You will be prompted to enter the user password.
Password for ridgerun@//192.168.121.118/ridgerun: ********
Add a Samba server to an external partition
These instructions are specifically to add external partitions such as SSD or SD cards.
Create a new user for the partition. For instance, it will be called "ridgerun" for this example, and the sharefolder will be located in the partition location /media/partition_name:
sudo useradd -M -d /media/partition_name -s /usr/sbin/nologin -G sambashare ridgerun
Change the ownership to ridgerun:
sudo chown ridgerun:sambashare /media/partition
Add the account to the database, and add a new password
sudo smbpasswd -a ridgerun
Enable the account:
sudo smbpasswd -e ridgerun
Edit the smb.conf file in order to add the $USER, this will fixed the lack permissions from the client side:
sudo vi /etc/samba/smb.conf
The user "nvidia" was added to the smb.conf. This is the user of the platform where the Samba server is running, for this example it was running on a Jetson Xavier AGX which user's name was "nvidia". You can find the user information under the media/partition lives by typing:
ls -l /media/
It will show you the user information and its permissions:
drwxr-xr-x 4 nvidia root 16384 dic 31 1969 partition_name
Add the user to the "force user" variable within the smb.conf. This allows to share partitions such as Solid State Disks, which usually works under some user or group permissions.
# Change this to the workgroup/NT-domain name your Samba server will part of workgroup = WORKGROUP + force user = nvidia
This also helps to troubleshoot when the mounting server on the local PC throws permissions problems. |
Add the new user and its location to the smb.conf file:
+[user] + path = /media/partition_name + browseable = yes + read only = no + force create mode = 0660 + force directory mode = 2770 + valid users = @sambashare
Finally, restart the service:
sudo service smbd restart
To connect to this new sharefolder from another location you can do it by using the smbclient or by mounting the sharefolder on a local folder. Simple implementation example
This is an example of a local PC mounting a Samba server that is running on a Jetson AGX platform. In particular, this approach is preferred over running a Samba Client on a local PC to connect to a Samba Server, due to its flexibility to edit files and directories on both ways.
- The first step is to create a samba user on the Jetson platform. I named the user "ridgerun", for future references. Follow the steps on 3.1 Creating Samba Users section.
- Then, edit the /etc/samba/smb.conf file by adding the recently created user to the force user directive. Like this:
# Change this to the workgroup/NT-domain name your Samba server will part of workgroup = WORKGROUP force user = ridgerun
- Mount the Samba Server on the local PC. Follow the steps on 5. Mounting the Samba share.
sudo mount -t cifs -o username=ridgerun //192.162.100.233/ridgerun /mnt/smbmount [sudo] password for user: Password for ridgerun@//192.162.100.233/ridgerun: ******
- Create a directory from the Jetson side:
root@jetson:/samba/ridgerun# mkdir Hello_Client root@jetson:/samba/ridgerun# ls Hello_Client
- Now, you have access to the Samba Server running on the Jetson:
$ cd /mnt/smbmount/ $ ls Hello_Client
You can create files and edit them on both sides:
touch hello_server.txt vi hello_server.txt
This simple example demonstrated how to share and edit files and directories between two platforms over a same network.
For direct inquiries, please refer to the contact information available on our Contact page. Alternatively, you may complete and submit the form provided at the same link. We will respond to your request at our earliest opportunity.
Links to RidgeRun Resources and RidgeRun Artificial Intelligence Solutions can be found in the footer below.