Reader small image

You're reading from  Mastering Ubuntu Server - Fourth Edition

Product typeBook
Published inSep 2022
PublisherPackt
ISBN-139781803234243
Edition4th Edition
Concepts
Right arrow
Author (1)
Jay LaCroix
Jay LaCroix
author image
Jay LaCroix

Jeremy "Jay" LaCroix is a technologist and open-source enthusiast, specializing in Linux. He has a net field experience of 20 years across different firms as a Solutions Architect and holds a master's degree in Information Systems Technology Management from Capella University. In addition, Jay also has an active Linux-focused YouTube channel with over 250K followers and over 20M views, available at LearnLinuxTV, where he posts instructional tutorial videos and other Linux-related content. He has also written Linux Mint Essentials and Mastering Linux Network Administration, published by Packt Publishing.
Read more about Jay LaCroix

Right arrow

Sharing and Transferring Files

In the previous chapter, we looked at what’s involved in the process of setting up a few network services, such as DHCP and DNS. Those are two important components of a network, but there are quite a few different types of applications and resources you can make available on your network to further enhance it. A file server is one such example, which can give your users a central place to store critical files and can even enhance collaboration.

Perhaps you’ve used a file server before, or even set one up on a different platform. With Ubuntu Server, there are multiple methods to not only store files, but also to transfer files from one node to another over a network link. In this chapter, we’ll look into setting up a central file server using both Samba and NFS, as well as how to transfer files between nodes with utilities such as scp and rsync. We’ll also go over some situations in which one solution may work better for...

File server considerations

When it comes to setting up a file server, the process is a matter of setting up some sort of daemon to accept connections and share specific directories, and ensure the appropriate users are able to access those directories. You’ll also implement permissions to determine who can access specific directories, and what type of access they will have (read/write, read-only, and so on). When deciding how to share the files, it’s generally a choice between two common technologies that can facilitate the actual sharing, Samba and NFS.

All in all, there’s nothing stopping you from hosting both Samba and NFS shares on a single server. The two technologies can actually co-exist on the same device. However, each of the two popular solutions is more appropriate for particular use cases. Before we get started with setting up our file server, we should first understand the differences between Samba and NFS, so we can make an informed decision...

Sharing files with Windows users via Samba

In this section, I’ll walk you through setting up your very own Samba file server. I’ll also go over a sample configuration to get you started so that you can add your own shares. First, we’ll need to make sure that the samba package is installed on our server:

sudo apt install samba 

When you install the samba package, you’ll have a new daemon installed on your server, smbd. The smbd daemon will be automatically started and enabled for you. You’ll also be provided with a default configuration file for Samba, located at /etc/samba/smb.conf. For now, I recommend stopping samba since we have yet to configure it:

sudo systemctl stop smbd 

Since we’re going to configure Samba from scratch, we should start with an empty configuration file. Let’s back up the original file, rather than overwrite it. The default file includes some useful notes and samples, so we should keep it around...

Setting up NFS shares

An alternative to Samba is NFS. It’s a great method of sharing files from a Linux or Unix server to another Linux or Unix server. As I mentioned earlier in the chapter, Windows systems can access NFS shares as well, but that requires an add-on to be enabled. Therefore, NFS is preferred in a Linux or Unix environment, since it fully supports Linux and Unix-style permissions. As you can see from our dive into Samba earlier, we essentially forced all shares to be treated as being accessed by a particular user, which was messy, but was the easiest example of setting up a Samba server without also walking you through setting up a complicated Windows Active Directory deployment. Samba can certainly support per-user access restrictions and benefits greatly from a centralized directory server, though that would basically be a book of its own! NFS integrates better in a non-mixed environment.

Earlier, we set up a parent directory in our filesystem to house...

Transferring files with rsync

Of all the countless tools and utilities available in the Linux and Unix world, few are as beloved as rsync. This is a utility that you can use to copy data from one place to another very easily, and there are many options available to allow you to be very specific about how you want the data to be transferred. Examples of its many use cases include copying files while preserving permissions, copying files while backing up replaced files, and even setting up incremental backups. If you don’t already know how to use rsync, you’ll probably want to get lots of practice with it, as it’s something you’ll soon see will be indispensable during your career as a Linux administrator, and it is also something that the Linux community generally assumes you already know. Thankfully, rsync is not hard to learn. Most administrators can learn the basic usage in about an hour or less, but the countless options available will lead you to learn...

Transferring files with SCP

A useful alternative to rsync is the Secure Copy (SCP) utility, which comes bundled with the OpenSSH client. It allows you to quickly copy files from one node to another. While rsync also allows you to copy files to other network nodes via SSH, SCP is more practical for one-off tasks; rsync is geared toward more complex jobs. If your goal is to send a single file or a small number of files to another machine, SCP is a great tool you can use to get the job done. If nothing else, it’s yet another item for your administration toolbox. To utilize SCP, we’ll use the scp command. Since you most likely already have the OpenSSH client installed, you should already have the scp command available. If you execute which scp, you should receive the following output:

/usr/bin/scp 

If you don’t see any output, make sure that the openssh-client package is installed.

Using SCP is very similar in nature to rsync. The command requires a source...

Summary

In this chapter, we explored multiple ways of accessing remote resources. Just about every network has a central location for storing files, and we explored two ways of accomplishing this with NFS and Samba. Both NFS and Samba have their place in the data center and are very useful ways in which we can make resources on a server available to our users who need to access them. We also talked about rsync and scp, two great utilities for transferring data without needing to set up a permanent share.

Next up is Chapter 13, Managing Databases. Now that we have all kinds of useful services running on our Ubuntu Server network, it’s only fitting that we take a look at serving databases as well. Specifically, we’ll look at MariaDB. See you there!

Relevant videos

Further reading

Join our community on Discord

Join our community’s Discord space for discussions with the author and other readers:

https://packt.link/LWaZ0

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Mastering Ubuntu Server - Fourth Edition
Published in: Sep 2022Publisher: PacktISBN-13: 9781803234243
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime

Author (1)

author image
Jay LaCroix

Jeremy "Jay" LaCroix is a technologist and open-source enthusiast, specializing in Linux. He has a net field experience of 20 years across different firms as a Solutions Architect and holds a master's degree in Information Systems Technology Management from Capella University. In addition, Jay also has an active Linux-focused YouTube channel with over 250K followers and over 20M views, available at LearnLinuxTV, where he posts instructional tutorial videos and other Linux-related content. He has also written Linux Mint Essentials and Mastering Linux Network Administration, published by Packt Publishing.
Read more about Jay LaCroix