Set up NFS Share on Ubuntu 16.04 LTS

Install & Configure NFS Server

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 running
 commands as the root user.

On the first Ubuntu 16.04 computer, install nfs-kernel-server packages.

root@pemulalinux:~# apt-get -y install nfs-kernel-server

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.

/var/nfsshare 10.150.100.0/24(rw,sync,no_subtree_check)

You can get to know all the option on the man page (man exports) or here.
Use the below command to export the shared directories.

root@pemulalinux:~# exportfs -ra

Configure NFS client

We need to install the nfs-common package on the client machine to mount a remote filesystem.

Make sure you are running commands as the root user.

root@ubuntu:~# apt-get -y install nfs-common

Create a directory /var/nfsshare on the client machine to mount the shared directory.

root@ubuntu:~# mkdir /var/nfsshare

Use mount command to mount a shared directory /var/nfsshare from NFS server (10.150.100.16) in /var/nfsshare on the client machine.

root@ubuntu:~# mount -t nfs 10.150.100.16:/var/nfsshare /var/nfsshare

Verify the mounted share on the client machine using the mount command.

root@ubuntu:~# mount | grep nfs

Output:

You can also use df command to check the mounted NFS shares.

root@ubuntu:~# df -hT

Output:

Automount NFS Shares

To mount NFS shares automatically on every reboot, you need to edit /etc/fstab file on your client system.

root@ubuntu:~# vi /etc/fstab

Add the below line at the end of the file.

10.150.100.16:/var/nfsshare /var/nfsshare defaults 0 0

Save and close the file.

Reboot the client machine and check whether NFS share is automatically mounted or not.

root@ubuntu:~# reboot

Install GNOME Desktop Environment & Xrdp Server on Centos 6

Desktop Environment is not neccessary for Server usage, though. But Sometimes installation or using an application requires Desktop Environment, then build Desktop Environment as follows.

Install GNOME Desktop Environment on here.

[root@pemulalinux ~]#  yum -y groupinstall “X Window System

[root@pemulalinux ~]# yum -y groupinstall “Desktop”

[root@pemulalinux ~]# yum -y groupinstall “General Purpose Desktop”

 Before we start to remote we need to install xrdp server to connect to CentOS from Windows clients with the Remote Desktop function.

# install from EPEL

[root@pemulalinux ~]# yum –enablerepo=epel -y install xrdp tigervnc-server

[root@pemulalinux ~]# /etc/rc.d/init.d/xrdp start
Starting xrdp: [ OK ]
Starting xrdp-sesman: [ OK ]

[root@pemulalinux ~]# chkconfig xrdp on

 If xrdp server and gnome already installed lets try command this.

[root@pemulalinux ~]# startx

 Connect from Windows clients. For example on Windows 7, input “Remote Desktop” to start the remote desktop function.

 Input the hostname or IP address you’d like to connect and push the “Connect” button.

Remote Desktop [pemulalinux.pic1]

 Input a user which is in CentOS to authenticate.

xrdp login [pemulalinux.pic2]

 Just connected. If failed to login at first time (sometimes happens at first login), retry to login again.

Desktop Centos [pemulalinux.pic3]

Howto Make a Directory on Linux

"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 dirname
OR
mkdir dirname1 dirname2
OR
mkdir [option] dieNameHere
OR
mkdir -p dir1/dir2/dir3

Examples

Open a terminal and use the mkdir command to create empty directories. The following command would create a directory called foo:

$ mkdir foo

How To Create a Sudo User on CentOS

Introduction

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

  1. Log in to your server as the root user.
    • ssh root@server_ip_address

  2. 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.

      adduser username

    > Use the passwd command to update the new user’s password.

    passwd username

    > 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.
    New password:
    Retype new password:
    passwd: all authentication tokens updated successfully.

How To Update the Kernel in CentOS / Red Hat

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!

How To Check the Kernel Version in Linux / Ubuntu / CentOS

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 :

uname -r

You should receive a result similar to the following:

2.6.32-431.11.2.el6.x86_64

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

Install vsftpd for CentOS

Install and run vsftpd

Use the group installation that is available in the YUM package manager.

  1. Run the following command to install everything you need :
    # sudo yum install vsftpd
  2. 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.

  1. 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

  2. Ensure that users are jailed in their home directory by adding the following entry to the bottom of the file :

    chroot_local_user=YES

  3. Save the /etc/vsftpd/vsftpd.conf file.
  4. 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

  1. Open ports in your firewall by running the following command :
    # sudo iptables -I INPUT 4 -m tcp -p tcp -m conntrack --ctstate NEW --dport 21 -j ACCEPT
  2. Save your configuration :
    # sudo service iptables save
  3. Open the /etc/sysconfig/iptables-config file in your favorite editor.
  4. Verify that the IPTABLES_MODULES variable is specified as ip_conntrack_ftp (CentOS 5) or nf_conntrack_ftp (CentOS 6), as shown in the following examples :> Centos 5 (ip_conntrack_ftp):
    IPTABLES_MODULES="ip_conntrack_ftp"
    

    >Centos 6 (nf_conntrack_ftp):

    IPTABLES_MODULES=”nf_conntrack_ftp”
  5. Save the iptables-config file and restart iptables:
    # sudo service iptables restart

    Access your server through FTP

    Use one of the following methods to access the server.

    Using a browser

    Enter the name of your FTP site into a browser address bar, as shown in the following screenshot and supply the login credentials when prompted.

    Open FTP via browser

    Using an FTP client

    Use one of the many low-cost or free FTP applications, such as CyberDuck and Fireuploader, that are available for download.

    Using the command line

    Use the following syntax to open an FTP session from the command line:

    ftp example.com
    

    To close the FTP session, type exit in the session window.

 

 

 

 

 

 

 

 

 

Change a server’s hostname in CentOS 6

  1. Using a text editor, open the server’s /etc/sysconfig/network file.
    # sudo nano /etc/sysconfig/network
  2. Modify the HOSTNAME= value to match your FQDN hostname.
    HOSTNAME=myserver.domain.com
  3. For internal networking, change the host that is associated with the main IP address for your server (found at /etc/hosts).
    127.0.0.1             localhost       localhost.localdomain 
    
    123.45.67.89      hostname.domain.com hostname 
    
    ~
    
     ~
    
     ~
    
     ~
    
     -- INSERT --                                                  2,43-57 ALL
  4. Run the hostname command. This command lets you change the hostname on the server that the command line remembers, but it does not actively update all programs that are running under the old hostname.
    [root@defiant ~]# hostname hostname.domain.com
    
    [root@defiant ~]# hostname
    
    hostname.domain.com
    
    [root@defiant ~]#
  5. Restart networking on your server to ensure that changes will persist on restart.
    # /etc/init.d/network restart

Installing LAMP (Linux, Apache, MariaDB, PHP/PhpMyAdmin) in RHEL/CentOS 7.0

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
Install Apache Web Server

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 
OR 
# service httpd status|start|stop|restart|reload 
OR 
# apachectl configtest| graceful
Start Apache Web Server

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.

# firewall-cmd --permanent --add-service=http
# systemctl restart firewalld
Enable Firewall in CentOS 7

Other important Firewalld options are presented below:

# firewall-cmd --state
# firewall-cmd --list-all
# firewall-cmd --list-interfaces
# firewall-cmd --get-service
# firewall-cmd --query-service service_name
# firewall-cmd --add-port=8080/tcp

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.

Apache Default Page

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
Apache Directory Listing

6. Close the file, restart Apache service to reflect changes and reload your browser page to see the final result.

# systemctl restart httpd
Apache Index File

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
Install PHP in CentOS 7

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.

# yum install php php-mysql php-pdo php-gd php-mbstring
Install PHP Modules
Install PHP mbstring Module

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.

# echo "<?php phpinfo(); ?>" > /var/www/html/info.php
# systemctl restart httpd
Check PHP Info in CentOS 7

10. If you get an error on PHP Date and Timezone, open php.ini configuration file, search and uncomment date.timezone statement, append your physical location and restart Apache daemon.

# nano /etc/php.ini

Locate and change date.timezone line to look like this, using PHP Supported Timezones list.

date.timezone = Continent/City
Set Timezone in PHP

Step 3: Install and Configure MariaDB Database

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
Install MariaDB in CentOS 7

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).

# systemctl start mariadb
# mysql_secure_installation
Start MariaDB Database
Secure MySQL Installation

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
Connect MySQL Database

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.

# yum install http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el7.rf.x86_64.rpm

After enabling rpmforge repository, next install PhpMyAdmin.

# yum install phpmyadmin
Enable RPMForge Repository

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
Allow Remote PhpMyAdmin Access

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/.

# nano /etc/httpd/conf.d/phpmyadmin.conf
# systemctl restart  httpd
Add Blowfish in PhpMyAdmin
PhpMyAdmin Dashboard

Step 5: Enable LAMP System-wide

17. If you need MariaDB and Apache services to be automatically started after reboot issue the following commands to enable them system-wide.

# systemctl enable mariadb
# systemctl enable httpd
Enable Services System Wide

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.