|
| 1 | +--- |
| 2 | +id: install-and-configure-samba |
| 3 | +summary: Install and configure Samba to share files across a network. |
| 4 | +categories: server |
| 5 | +tags: tutorial,installation,ubuntu,file server,samba |
| 6 | +difficulty: 1 |
| 7 | +status: Published |
| 8 | +published: 2017-12-01 |
| 9 | +author: Aden Padilla <adenpadilla@gmail.com> |
| 10 | + |
| 11 | +--- |
| 12 | + |
| 13 | +# Install and Configure Samba |
| 14 | + |
| 15 | +## Overview |
| 16 | +Duration: 1:00 |
| 17 | + |
| 18 | +A Samba file server enables file sharing across different operating systems over a network. It lets you access your desktop files from a laptop and share files with Windows and macOS users. |
| 19 | + |
| 20 | +This guide covers the installation and configuration of Samba on Ubuntu. |
| 21 | + |
| 22 | +### What you'll learn |
| 23 | +- How to set up a Samba file server |
| 24 | +- How to share files across a local network |
| 25 | + |
| 26 | +### What you'll need |
| 27 | +- Ubuntu 16.04 LTS |
| 28 | +- A Local Area Network (LAN) to share files over |
| 29 | + |
| 30 | +If you have everything ready, let's dive straight into the installation process on the next step! |
| 31 | + |
| 32 | +## Installing Samba |
| 33 | +Duration: 1:00 |
| 34 | + |
| 35 | +To install Samba, we run: |
| 36 | +```bash |
| 37 | +sudo apt update |
| 38 | +sudo apt install samba |
| 39 | +``` |
| 40 | +We can check if the installation was successful by running: |
| 41 | +```bash |
| 42 | +whereis samba |
| 43 | +``` |
| 44 | +The following should be its output: |
| 45 | +```bash |
| 46 | +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 |
| 47 | +``` |
| 48 | + |
| 49 | +## Setting up Samba |
| 50 | +Duration: 2:00 |
| 51 | + |
| 52 | +Now that Samba is installed, we need to create a directory for it to share: |
| 53 | +```bash |
| 54 | +mkdir /home/<username>/sambashare/ |
| 55 | +``` |
| 56 | +The command above creates a new folder `sambashare` in our home directory which we will share later. |
| 57 | + |
| 58 | +The configuration file for Samba is located at `/etc/samba/smb.conf`. To add the new directory as a share, we edit the file by running: |
| 59 | +```bash |
| 60 | +sudo nano /etc/samba/smb.conf |
| 61 | +``` |
| 62 | +At the bottom of the file, add the following lines: |
| 63 | +``` |
| 64 | +[sambashare] |
| 65 | + comment = Samba on Ubuntu |
| 66 | + path = /home/username/sambashare |
| 67 | + read only = no |
| 68 | + browsable = yes |
| 69 | +``` |
| 70 | +Then press `Ctrl-O` to save and `Ctrl-X` to exit from the *nano* text editor. |
| 71 | + |
| 72 | + |
| 73 | +### What we've just added |
| 74 | +- [sambashare]: The name inside the brackets is the name of our share. |
| 75 | +- comment: A brief description of the share. |
| 76 | +- path: The directory of our share. |
| 77 | +- read only: Permission to modify the contents of the share folder is only granted when the value of this directive is `no`. |
| 78 | +- browsable: When set to `yes`, file managers such as Ubuntu's default file manager will list this share under "Network". |
| 79 | + |
| 80 | +Now that we have our new share configured, save it and restart Samba for it to take effect: |
| 81 | +```bash |
| 82 | +sudo service smbd restart |
| 83 | +``` |
| 84 | + |
| 85 | +## Setting up User Accounts and Connecting to Share |
| 86 | +Duration: 1:00 |
| 87 | + |
| 88 | +Since Samba doesn't use the system account password, we need to set up a Samba password for our user account: |
| 89 | +```bash |
| 90 | +sudo smbpasswd -a username |
| 91 | +``` |
| 92 | + |
| 93 | +negative |
| 94 | +: **Note** |
| 95 | +Username used must belong to a system account, else it won't save. |
| 96 | + |
| 97 | +### Connecting to Share |
| 98 | +On Ubuntu: |
| 99 | +Open up the default file manager and click *Connect to Server* then enter: |
| 100 | + |
| 101 | + |
| 102 | +On macOS: |
| 103 | +In the Finder menu, click *Go > Connect to Server* then enter: |
| 104 | + |
| 105 | + |
| 106 | +On Windows, open up File Manager and edit the file path to: |
| 107 | +```address |
| 108 | +\\ip-address\sambashare |
| 109 | +``` |
| 110 | +Note: `ip-address` is the Samba server IP address and `sambashare` is the name of the share. |
| 111 | + |
| 112 | +You'll be prompted for your credentials. Enter them to connect! |
| 113 | + |
| 114 | + |
| 115 | +### If you'd like to take your configuration further... |
| 116 | +- [Samba Server Guide](https://help.ubuntu.com/community/Samba/SambaServerGuide) |
0 commit comments