NFS stands for Network File System. This tutorial is going to show you how to configure NFS share on Ubuntu 16.04 so that other computes in your local network can access files and directories on the Ubuntu 16.04 system. We will see how to configure the server side and the client side.
NFS allows directories and file systems to be shared across a local network. NFS can also be set up over the Internet but it’s not secure. In this tutorial, we will set up NFS file share in a home network with two Ubuntu 16.04 computers.
Make sure you are runningcommands as the root user.
On the first Ubuntu 16.04 computer, install nfs-kernel-server packages.
Let’s create a directory we want to share with client machines. Here, we will create a new directory named /var/nfsshare .
root@pemulalinux:~# mkdir /var/nfsshare
Allow client machines to read and write to the created directory.
root@pemulalinux:~# chmod 777 /var/nfsshare
Then edit the exports file with nano text editor. The exports files tell NFS server which directories or file systems will be shared to client.
root@pemulalinux:~# vi /etc/exports
The syntax is as follows
/path/to/directory client-IP address(options)
For example, you want to share you home directory or another directory to the second Ubuntu computer with IP address 10.150.100.17, then put the following line at the end of the file, then save the configuration.
"How do I make directory under Linux operating systems using the command prompt or bash shell?"
You need to use the mkdir command to create new folders or directories under Linux operating systems. A directory (also known as folder in MS-Windows/OS X) is nothing but a container for other directories and files.
mkdir command Syntax
The mkdir command has the following syntax:
mkdir dirname1 dirname2
mkdir [option] dieNameHere
mkdir -p dir1/dir2/dir3
Open a terminal and use the mkdir command to create empty directories. The following command would create a directory called foo:
The sudo command provides a mechanism for granting administrator privileges, ordinarily only available to the root user, to normal users. This guide will show you the easiest way to create a new user with sudo access on CentOS, without having to modify your server’s sudoers file. If you want to configure sudo for an existing user, simply skip to step 3.
Steps to Create a New Sudo User
Log in to your server as the root user.
Use the adduser command to add a new user to your system.
> Be sure to replace username with the user that you want to create.
> Use the passwd command to update the new user’s password.
> Set and confirm the new user’s password at the prompt. A strong password is highly recommended!
Set password prompts:
Changing password for user username.
Retype new password:
passwd: all authentication tokens updated successfully.
Updating the kernel on Red Hat Linux or CentOS Linux is a very simple process. Most commonly you will use the following command in the case of a security vulnerability, or perhaps just to verify that you’re running the most up-to-date kernel:
yum -y update kernel
In this case, yum is the rpm-based package manager for both Red Hat and CentOS, -y, –assumeyes gives yes as an answer to any question which would be asked by running the command, update is for updating the package, and kernel is the package you’re updating!
Assuming your server needed a new kernel and was thus upgraded, reboot your server to complete the process!
The following command works with all Linux distributions, such as Red Hat, CentOS, Debian, and Ubuntu. It also works on other UNIX-like operating systems such as HPUX, FreeBSD, OpenBSD, Solaris, etc. Use the following command to check which kernel version your server is currently running :
You should receive a result similar to the following:
The output can be interpreted with the following key:
2 – Kernel Version
6 – Major Revision
32 – Minor Revision
431.11.2.el6 – Fix/Revision Detail
Per the manual page, uname can also give the following information:
-a, --all print all information
-s, --kernel-name print the kernel name
-n, --nodename print the network node hostname
-r, --kernel-release print the kernel release
-v, --kernel-version print the kernel version
-m, --machine print the machine hardware name
-p, --processor print the processor type or "unknown"
-i, --hardware-platform print the hardware platform or "unknown"
-o, --operating-system print the operating system
--help display this help and exit
--version output version information and exit
Use the group installation that is available in the YUM package manager.
Run the following command to install everything you need :
# sudo yum install vsftpd
To start vsftpd, run the following command :
# sudo service vsftpd start
Now that you have a working installation of vsftpd already on the server. Now you can make a few of configuration changes for security and convenience.
Set the vsftp service to start on reboot
You can use the chkconfig tool to view which services start automatically when the server starts, and on which run level they start. To get vsftpd to start on the most common run levels (3,4,5), run the following command :
# sudo chkconfig vsftpd on
Verify the “on” status by checking the chkconfig output for vsftpd :
# chkconfig --list vsftpd
The standard vsftpd configuration file and all subsequent files for CentOS reside in the /etc/vsftpd/directory. The most important file in this directory is vsftpd.conf. You need to make two changes to this file for security and convenience. These are the changes described in the next two sections.
To get started, open the /etc/vsftpd/vsftpd.conf file in your favorite text editor.
Disable anonymous users
We recommend disabling anonymous FTP, unless you have a specific requirement to use it.
Change the value for anonymous_enable to No, as follows :
# Allow anonymous FTP? (Beware - allowed by default if you comment this out). anonymous_enable=NO
Restrict user access
Now configure vsftpd to be able to chroot (commonly referred to as jailing) users to their home directories for security and privacy.
Change the value of chroot_list_enable to No, as follows :
# You may specify an explicit list of local users to chroot() to their home # directory. If chroot_local_user is YES, then this list becomes a list of # users to NOT chroot(). chroot_list_enable=NO # (default follows) chroot_list_file=/etc/vsftpd/chroot_list
Ensure that users are jailed in their home directory by adding the following entry to the bottom of the file :
Save the /etc/vsftpd/vsftpd.conf file.
So that you do not get an error when restarting, create the chroot_list file, as follows :
sudo touch /etc/vsftpd/chroot_list
Configure the firewall
Open ports in your firewall by running the following command :
Step 1: Install Apache Server with Basic Configurations
1. Install Apache 2.4 httpd service binary package provided form official repositories using the following command.
# yum install httpd
2. After yum manager finish installation, use the following commands to manage Apache daemon, since CentOS 7.0 both migrated their init scripts from SysV to systemd – you can also use SysV and Apache scripts the same time to manage the service.
# systemctl status|start|stop|restart|reload httpd
# service httpd status|start|stop|restart|reload
# apachectl configtest| graceful
3. On the next step start Apache service using systemd init script and open CentOS 7.0 Firewall rules using firewall-cmd, which is the default command to manage iptables through firewalld daemon.
# firewall-cmd --add-service=http
NOTE: Make notice that using this rule will lose its effect after a system reboot or firewalld service restart, because it opens on-fly rules, which are not applied permanently. To apply consistency iptables rules on firewall use –permanent option and restart firewalld service to take effect.
4. To verify Apache functionality open a remote browser and type your server IP Address using HTTP protocol on URL (http://server_IP), and a default page should appear like in the screenshot below.
5. For now, Apache DocumentRoot path it’s set to /var/www/html system path, which by default doesn’t provide any index file. If you want to see a directory list of your DocumentRoot path open Apache welcome configuration file and set Indexes statement from – to + on <LocationMach> directive, using the below screenshot as an example.
# nano /etc/httpd/conf.d/welcome.conf
6. Close the file, restart Apache service to reflect changes and reload your browser page to see the final result.
# systemctl restart httpd
Step 2: Install PHP5 Support for Apache
7. Before installing PHP5 dynamic language support for Apache, get a full list of available PHP modules and extensions using the following command.
# yum search php
8. Depending on what type of applications you want to use, install the required PHP modules from the above list, but for a basic MariaDB support in PHP and PhpMyAdmin you need to install the following modules.
9. To get a full information list on PHP from your browser, create a info.php file on Apache Document Root using the following command from root account, restart httpd service and direct your browser to the http://server_IP/info.php address.
11. Red Hat Enterprise Linux/CentOS 7.0 switched from MySQL to MariaDB for its default database management system. To install MariaDB database use the following command.
# yum install mariadb-server mariadb
12. After MariaDB package is installed, start database daemon and use mysql_secure_installation script to secure database (set root password, disable remotely logon from root, remove test database and remove anonymous users).
13. To test database functionality login to MariaDB using its root account and exit using quit statement.
mysql -u root -p
MariaDB > SHOW VARIABLES;
MariaDB > quit
Step 4: Install PhpMyAdmin
14. By default official RHEL 7.0 or CentOS 7.0 repositories doesn’t provide any binary package for PhpMyAdmin Web Interface. If you are uncomfortable using MySQL command line to manage your database you can install PhpMyAdmin package by enabling CentOS 7.0 rpmforge repositories using the following command.
After enabling rpmforge repository, next install PhpMyAdmin.
# yum install phpmyadmin
15. Next configure PhpMyAdmin to allow connections from remote hosts by editing phpmyadmin.conf file, located on Apache conf.d directory, commenting the following lines.
# nano /etc/httpd/conf.d/phpmyadmin.conf
Use a # and comment this lines.
# Order Deny,Allow
# Deny from all
# Allow from 127.0.0.1
16. To be able to login to PhpMyAdmin Web interface using cookie authentication method add a blowfish string to phpmyadmin config.inc.php file like in the screenshot below using the generate a secret string, restart Apache Web service and direct your browser to the URL address http://server_IP/phpmyadmin/.
That’s all it takes for a basic LAMP installation on Red Hat Enterprise 7.0 or CentOS 7.0. The next series of articles related to LAMP stack on CentOS/RHEL 7.0 will discuss how to create Virtual Hosts, generate SSL Certificates and Keys and add SSL transaction support for Apache HTTP Server.