Linux file server construction (Ubuntu & Samba)

I installed Linux (Ubuntu 20.04.1) on Windows using virtualbox, so I tried to build a file server. It is a memo of.

Create a shared directory

$sudo mkdir /home/share
$sudo chmod 0777 /home/share

I created a share directory under home and granted access to that directory. Share the contents of this directory. (The name is arbitrary, please decide the share part as you like)

mkdir → create directory chmod → Change access authority

Samba installation

$ sudo apt-get -y install samba

File server settings

$ sudo vim /etc/samba/smb.conf

Open it with the above command and edit smb.conf. I think there is the following description on the 22nd line.

smb.conf


#======================= Global Settings =======================

[global]

## Browsing/Identification ###

Add the following description.

unix charset = UTF-8
dos charset = CP932

I will make it like this.

smb.conf


#======================= Global Settings =======================

[global]
unix charset = UTF-8
dos charset = CP932

## Browsing/Identification ###

Edit the following if necessary. I didn't need to edit it.

smb.conf


#Change this to the workgroup/NT-domain name your Samba server will part of
  workgroup = WORKGROUP

Write the value of the Winodws workgroup in WORKGROUP workgroup = You can check it below Control Panel-> System and Security-> System -> Computer name, domain and workgroup settings

There is the following description near the 38th line.

smb.conf


#### Networking ###

This item seems to be used to limit the connection source IP address. I didn't edit this time.

Add the following to the end of the file:

smb.conf


[Share]
   path = /home/share
   writable = yes
   guest ok = yes
   guest only = yes
   create mode = 0777
   directory mode = 0777

For [Share], give any name to the folder name for sharing. For path, enter the path of the directory you want to share first.

Restart the file server

$ sudo systemctl restart smbd
$ sudo systemctl enable smbd

Confirm server name

Check the server name on linux.

$ hostname
server name

Access files on Windows

Open Explorer in Windows and from Map Network Drive Click Map Network Drive.

In the folder field, specify "\ server name \ shared folder name".

The server name was confirmed on Linux earlier. The folder name is the [Share] part you specified earlier. (In this case, share)

The user authentication screen will appear and you can enter it. You should now be able to access the file.

bonus

This is a method to restrict user access in groups.

Creating a group

$ sudo groupadd share

The share group has been created.

File server settings

Edit what you added at the end of smb.conf.

smb.conf


[Share]
   path = /home/share
   writable = yes
   guest ok = no
   create mode = 0777
   directory mode = 0777
   valid users = @share

Specify the group name that can be authenticated by valid users. This time, users who belong to the share group can access it.

Add user

Only if you want to create a new user. Even users who have made it from the beginning are okay.

$sudo useradd -m username
$sudo passwd username

After this, enter the password twice and the user will be created. Users should have the same name. A home directory is created by adding the useradd option -m. (-m is not necessary)

Add user to group

$ sudo usermod -aG share username

The user can now be registered in the group.

Add user to samba

$ sudo pdbedit -a username

Enter the password twice and you're done. (I was able to access it with smbpasswd instead of pdbedit.)

Now you can restrict access by authentication when accessing from Windows.

Reference article

https://qiita.com/k-Mata/items/8bee9e02e74565b6c147 https://qiita.com/msrks/items/1385cf13258dd1a0da08 https://www.server-world.info/query?os=Ubuntu_16.04&p=samba https://linuxfan.info/ip-address https://www.server-world.info/query?os=Ubuntu_18.04&p=samba&f=2 https://renoji.com/IT.php?Contents=OS_CentOS/Server_File/Samba_UserRegistration.html https://qiita.com/orangain/items/056db6ffc16d765a8187 https://eng-entrance.com/linux-user-add

Recommended Posts

Linux file server construction (Ubuntu & Samba)
Linux Web server construction (Ubuntu & Apache)
Ubuntu (18.04.3) Web server construction
Set up a file server on Ubuntu 20.04 using Samba
Ubuntu Linux 20.04
Linux server construction link summary (CentOS7)
The basics of building an in-house server for Linux (CentOS 8.1, openSUSE 15.1, Ubuntu 20.04)! File server with Samba
Build a Samba server on Arch Linux
Linux environment construction
Linux (CentOS) construction
Linux server command
[Linux] File search
[Samba] File sharing between Linux and Windows machines
Linux server load verification
Web server construction commentary
Hack Linux file descriptors
[Ubuntu 18.04] Tensorflow 2.0.0-GPU environment construction
About Linux environment construction (CentOS)
Device and Linux file system
First LAMP environment construction (Linux)
Linux file and directory permissions
Ubuntu14.04 + GPU + TensorFlow environment construction
Linux environment construction (on WSL environment)
Ubuntu / Linux laptop WiFi issues
Set up Ubuntu as a Linux cheat sheet and https server