{"id":2038,"date":"2021-09-30T09:31:57","date_gmt":"2021-09-30T06:31:57","guid":{"rendered":"https:\/\/upcloud.com\/global\/us\/resources\/tutorials\/transfer-files-linux-samba\/"},"modified":"2026-04-23T14:31:15","modified_gmt":"2026-04-23T13:31:15","slug":"transfer-files-linux-samba","status":"publish","type":"tutorial","link":"https:\/\/upcloud.com\/global\/resources\/tutorials\/transfer-files-linux-samba\/","title":{"rendered":"How to transfer files to Linux server using Samba"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Once you have your first Linux server up and running, you might be wondering how to transfer files or folders between your server and your local computer. Luckily, there\u2019s an easy solution by setting up a Samba file service on your Cloud Server.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Samba is a suite of Unix applications that speak the Server Message Block (SMB) protocol. Microsoft Windows operating systems and the OS\/2 operating system use SMB to perform client-server networking for file and printer sharing and associated operations.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In short, Samba helps you transfer files between your server and your local computer.&nbsp;In this tutorial, we\u2019ll show the steps to set up and configure your Cloud Server with Samba.<\/p>\n\n\n\n\n\n<h2 class=\"wp-block-heading\">Setting up your server<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">To begin, you need a Linux-based Cloud Server, this can be Ubuntu, Debian or Centos. You can find out more in our tutorial on <a href=\"https:\/\/upcloud.com\/global\/docs\/guides\/deploy-server\/\" target=\"_blank\" rel=\"noreferrer noopener\">how to create a new Cloud Server<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">When your server is live, <a href=\"https:\/\/upcloud.com\/global\/docs\/guides\/connecting-to-your-server\/\" target=\"_blank\" rel=\"noreferrer noopener\">log in using SSH<\/a> and continue by updating the server software.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>sudo apt update &amp;&amp; sudo apt upgrade<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Then install Samba with the following command.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>sudo apt install samba<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We can check if the installation was successful by looking up the installation location.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>whereis samba<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You should see an output similar to the example below.<br><code>samba: \/usr\/sbin\/samba \/usr\/lib\/samba \/etc\/samba \/usr\/share\/samba \/usr\/share\/man\/man7\/samba.7.gz \/usr\/share\/man\/man8\/samba.8.gz<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">With Samba installed, we will next configure the firewall.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Depending on your Linux distribution, you will have either ufw or firewalld. If you are running Ubuntu or Debian, UFW is the firewall of choice. CentOS on the other hand comes with firewalld.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code> sudo ufw allow 'Samba' <\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You should also allow SSH to prevent yourself from getting locked out.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code> sudo ufw allow ssh<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Next, enable the firewall and the configured rules.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code> sudo ufw enable <\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Now let\u2019s verify that the firewall is enabled as well as that Samba and SSH are allowed.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code> sudo ufw status verbose <\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The output should show something like the example below.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>Status: active<br>\nLogging: on (low)<br>\nDefault: deny (incoming), allow (outgoing), disabled (routed)<br>\nNew profiles: skip<br>\nTo                         Action      From<br>\n--                         ------      ----<br>\n137,138\/udp (Samba)        ALLOW IN    Anywhere<br>\n139,445\/tcp (Samba)        ALLOW IN    Anywhere<br>\n22\/tcp                     ALLOW IN    Anywhere<br>\n137,138\/udp (Samba (v6))   ALLOW IN    Anywhere (v6)<br>\n139,445\/tcp (Samba (v6))   ALLOW IN    Anywhere (v6)<br>\n22\/tcp (v6)                ALLOW IN    Anywhere (v6)<br>\n<\/code><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Verifying the default configuration<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Now let\u2019s start configuring Samba. However, before you start, you should always make a backup of the configuration file. This way you always have a way to restore the default settings if something goes wrong.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>sudo cp \/etc\/samba\/smb.conf{,.backup}<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Open the Samba configuration file with a text editor, for example, using nano with the following command.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code> sudo nano \/etc\/samba\/smb.conf <\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Then find the server role setting in the configuration file. The default value should be set to \u201cstandalone server\u201d.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code> ...<br>\n# Most people will want \"standalone sever\" or \"member server\".<br>\n# Running as \"active directory domain controller\" will require first<br>\n# running \"samba-tool domain provision\" to wipe databases and create a<br>\n# new domain.<br>\nserver role = standalone server<br>\n...<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Now let\u2019s test our configuration file with the command below.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>testparm<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>Load smb config files from \/etc\/samba\/smb.conf<br>\nLoaded services file OK.<br>\nServer role: ROLE_STANDALONE<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If there are no errors, your output should show the configuration as well as say \u201cLoaded services file ok\u201d like the example above.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Let\u2019s restart the related services to make sure everything is running.<br><code>sudo systemctl restart smbd<br>\nsudo systemctl restart nmbd<\/code><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Setting up Samba<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Now that Samba is installed, we need to create a directory for it to share, this makes it more organised.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>mkdir \/samba<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The command above creates a new folder called samba in the system root which we will share later.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Now let\u2019s set the group ownership of the shared directory to the sambashare group which was created during the Samba installation.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code> sudo chgrp sambashare \/samba<\/code><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Setting up a user account<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Samba utilises both Linux users and group permission as well as its own mechanism.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Let\u2019s create a user account using the <tt>useradd<\/tt> command. You can replace the example username upcloud with what you prefer.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>sudo useradd -M -d \/samba\/<span style=\"color: #ff0000;\">upcloud<\/span> -s \/usr\/sbin\/nologin -G sambashare <span style=\"color: #ff0000;\">upcloud<\/span><\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Breaking down the above command you just entered.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>-M do not create the user\u2019s home directory. We\u2019ll manually create this directory.<\/li>\n\n\n\n<li>-s \/usr\/sbin\/nologin \u2013 disable shell access for this user.<\/li>\n\n\n\n<li>-d \/samba\/upcloud \u2013 set the user\u2019s home directory to \/samba\/upcloud.<\/li>\n\n\n\n<li>-G sambashare \u2013 add the user to the sambashare group.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Now create a home directory for our user upcloud, then set the group of the folder to the samba share.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code> sudo mkdir \/samba\/upcloud <\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code> sudo chown upcloud:sambashare \/samba\/upcloud <\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Once this is done, we will set a password for the Samba user account<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>sudo smbpasswd -a upcloud<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You will be prompted to enter and confirm the user password.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code> New SMB password:<br>\nRetype new SMB password:<br>\nAdded user upcloud.<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Once the password is set and the user is created, enable the user with the following.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code> sudo smbpasswd -e upcloud <\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Next, we will set the setGID bit into the Samba directory. This will cause all files that are created in the shared directory to be owned by the group of the directory as opposed to the group of the owner.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code> sudo chmod 2770 \/samba\/upcloud <\/code><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Configuring Samba configuration file<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Lastly, we need to tell Samba where the shared directory is and who has permission to it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Open the Samba configuration file for editing.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code> sudo nano \/etc\/samba\/smb.conf <\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Add the following lines to the end of the file.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>[upcloud]<br>\npath = \/samba\/upcloud<br>\nbrowseable = no<br>\nread only = no<br>\nforce create mode = 0660<br>\nforce directory mode = 2770<br>\nvalid users = upcloud<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">When done, save the file and exit the editor.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Then restart the Samba services<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code> sudo systemctl restart smbd<br>\nsudo systemctl restart nmbd<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Once this is done, you are ready to connect to the Samba directory from your local machine.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Accessing Samba Share from Windows<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">For Windows users, you can connect to the Samba directory via the Windows Explorer.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1. Click on Start and search for \u201cFile Explorer\u201d then open it<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">2. In the window, right-click on \u201cThis PC\u201d then select \u201cMap network drive\u201d<br><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-22040 size-full\" src=\"https:\/\/upcloud.com\/media\/Cap1-1.jpg\" alt=\"-\" width=\"338\" height=\"405\" \/><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">3. A Popup will show asking for the credentials, Insert the user credentials, and set in the smbpasswd portion in Setting up User Accounts. For this eg, it will be \u201cupcloud\u201d<br><img loading=\"lazy\" decoding=\"async\" width=\"617\" height=\"450\" class=\"alignnone wp-image-22041 size-full\" src=\"https:\/\/upcloud.com\/media\/Cap3.jpg\" alt=\"-\" \/><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">4. The folder is now connected. I have added a file to the folder and the file is shown in my Windows network drive.<br><img loading=\"lazy\" decoding=\"async\" width=\"281\" height=\"59\" class=\"alignnone wp-image-22043 size-full\" src=\"https:\/\/upcloud.com\/media\/Cap5.jpg\" alt=\"-\" \/><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Accessing Samba Share from macOS<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In macOS, you can access the Samba Shares either from the command line or using the default macOS file manager Finder. The following steps show how to access the share using Finder.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1. Open \u201cFinder\u201d, select \u201cGo\u201d and click \u201cConnect To\u201d.<br><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-22167 size-full\" src=\"https:\/\/upcloud.com\/media\/Screenshot-2021-08-09-at-10.12.02-AM.png\" alt=\"-\" width=\"1480\" height=\"894\" \/><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">2. In \u201cConnect To\u201d, enter the address of the Samba share in the following format smb:\/\/samba_hostname_or_server_ip\/sharename.<br><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-22169 size-full\" src=\"https:\/\/upcloud.com\/media\/Screenshot-2021-08-09-at-10.09.51-AM-1.png\" alt=\"-\" width=\"972\" height=\"444\" \/><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">3. Make sure you select registered user and key in your Linux Credentials. In this eg, that will be upcloud<br><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-22170 size-full\" src=\"https:\/\/upcloud.com\/media\/Screenshot-2021-08-09-at-10.10.43-AM-1.png\" alt=\"-\" width=\"856\" height=\"550\" \/><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">4. Once it is connected you will be able to see the files from the server.<br><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-22166 size-full\" src=\"https:\/\/upcloud.com\/media\/Screenshot-2021-08-09-at-10.11.00-AM.png\" alt=\"-\" width=\"1206\" height=\"368\" \/><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Accessing Samba share from Ubuntu<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">On most Linux distributions, you can use a Samba command-line client. For example, smbclient can be installed on Ubuntu and other Debian-based systems using the following command.<br><code>sudo apt install smbclient<\/code><br>Once installed, you can connect to your Samba share with the command below.<br><code>smbclient \/\/samba_hostname_or_server_ip\/sharename -U username<\/code><br>For example, using the Cloud Server IP address and the \u201cupcloud\u201d share we created earlier. You\u2019ll also need to use the -U parameter for specifying the login username.<br><code>smbclient \/\/94.237.60.118\/upcloud -U upcloud<\/code><br>When prompted, enter your password<br><code>Enter WORKGROUPupcloud's password:<br> Try \"help\" to get a list of possible commands.<br> smb: &gt;<\/code><br>Alternatively, you can add your Samba share to most native file managers.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1. For example, on Ubuntu Nautilus, click the \u201c+Other Locations\u201d on the left panel. Then enter your Samba server address and share name in the \u201cConnect to Server\u201d field and click the Connect button.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/upcloud.com\/media\/samba-ubuntu-connect-to-server.webp\" alt=\"Samba Ubuntu connecting to server\" class=\"wp-image-22557\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">2. In the authentication window, select use Registered User and enter your username and password.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can also choose to have the username and password remembered either for the duration of the current login or permanently.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/upcloud.com\/media\/samba-registered-user.webp\" alt=\"Samba registered user authentication\" class=\"wp-image-22558\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">3. You are then ready to start uploading files to your Samba Linux server.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/upcloud.com\/media\/samba-ubuntu-share.webp\"><img decoding=\"async\" src=\"https:\/\/upcloud.com\/media\/samba-ubuntu-share.webp\" alt=\"Samba Ubuntu share\" class=\"wp-image-22559\" \/><\/a><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">You should now be able to transfer files from your local computer to your Cloud Server and back.<\/p>\n","protected":false},"author":35,"featured_media":22558,"comment_status":"open","ping_status":"closed","template":"","community-category":[223],"class_list":["post-2038","tutorial","type-tutorial","status-publish","has-post-thumbnail","hentry"],"acf":[],"_links":{"self":[{"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/tutorial\/2038","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/tutorial"}],"about":[{"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/types\/tutorial"}],"author":[{"embeddable":true,"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/users\/35"}],"replies":[{"embeddable":true,"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/comments?post=2038"}],"version-history":[{"count":1,"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/tutorial\/2038\/revisions"}],"predecessor-version":[{"id":6473,"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/tutorial\/2038\/revisions\/6473"}],"wp:attachment":[{"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/media?parent=2038"}],"wp:term":[{"taxonomy":"community-category","embeddable":true,"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/community-category?post=2038"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}