Archive for January, 2016

FTP server Setup

Posted: January 14, 2016 in Uncategorized

FTP server IP: 192.0.0.1

FTP client server IP: 192.0.0.2

Step 1: Install vsftp package

[root@192.0.0.1 ~]# yum install vsftpd

Step 2: Start the service

[root@192.0.0.1 ~]# /etc/init.d/vsftpd start

Step 3:  Need to edit the vsftpd configuration file.  

Before the edit, take the backup of existed file to any other location on the server

[root@192.0.0.1 ~]# cp /etc/vsftpd/vsftpd.conf /tmp/vsftpd.conf

Now edit the file,

[root@192.0.0.1 ~]# vi /etc/vsftpd/vsftpd.conf

Change the file as follows,

change the parameter YES to No for anonymous_enable  as below

anonymous_enable=NO

Uncomment the below lines 

ascii_upload_enable=YES
ascii_download_enable=YES

Add at the end of this file 
use_localtime=YES

Save the file and exit.

Step 4:   Create FTP user

[root@192.0.0.1 ~]# useradd ftpuser

Step 5: Create a password for ftp user

[root@192.0.0.1 ~]# passwd ftpuser

Step 6: Restart the service

[root@192.0.0.1 ~]# /etc/init.d/vsftpd restart

Step 7: Try to connect to FTP server from other Server. 

[root@192.0.0.2 ~]# ftp 192.0.0.1 21
Connected to .
220 (vsFTPd 2.2.2)
Name (192.168.198.133:bellurbis): ftpuser
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.

Common Errors while connecting to FTP server we may encounter

ftp: connect: No route to host

ftp: connect: Connection refused

500 OOPS: failed to open xferlog log file:/var/log/xferlog
500 OOPS: cannot change directory:/foo
500 OOPS: Connection closed by remote host.
500 OOPS: failed to open xferlog log file:/var/log/xferlog
553 could not create file error

These errors are just because of selinux enabled on FTP server.

There 2 ways to resolve this.

  1. Allow selinux to proceed with FTP
  2. Disable selinux
  1. Allow selinux to proceed with FTP 

Allow the FTP Without disabling selinux 

[root@www ~]# setsebool -P /home/ftpuser on

2. Disable selinux

To disable the selinux temporary, follow below steps

Disabling of SELINUX

Step 1: Open the selinux configuration file on FTP server

[root@192.0.0.1 ~]# vi /etc/selinux/config

Comment below line

SELINUX=enforcing

and add below line

SELINUX=disabled

Save the file and exit

Step 2: Disable selinux

[root@192.0.0.1 ~]# setenforce 0

Now try again to connect the server.

Note: To disable the selinux permanently we need to restart server

################################################################

 

NFS: Network File system, which is about sharing of one server’s file system on other server.

Simply mounting of one server’s directory on other server as its local directory

Installation:

NFS Server: 192.168.0.1

Client Server: 192.168.0.2

Serve side configuration:

Step 1:  Install the nfs and rpc (remote procedure call) packages

[root@192.168.0.1 ~]# yum install nfs-utils nfs-utils-lib

Step 2: Start RPC bind services

[root@192.168.0.1 ~]# /etc/init.d/rpcbind start

Step 3: Start NFS services

[root@192.168.0.1 ~]#  /etc/init.d/nfs start

Note: If we start NFS before starting of RPC bind service, it wont start and it triggers below error.

[root@192.168.0.1 ~]# /etc/init.d/nfs start
Starting NFS services: [ OK ]
Starting NFS quotas: Cannot register service: RPC: Unable to receive; errno = Connection refused
rpc.rquotad: unable to register (RQUOTAPROG, RQUOTAVERS, udp).
[FAILED]
Starting NFS mountd: [FAILED]
Starting NFS daemon: rpc.nfsd: writing fd to kernel failed: errno 111 (Connection refused)
rpc.nfsd: unable to set any sockets for nfsd
[FAILED]

Step 4: Add the rpcbind and nfs services at bootup

[root@192.168.0.1 ~]# chkconfig rpcbind on

[root@192.168.0.1 ~]# chkconfig nfs on

Step 5: Now create a directory which you want to share/mount on client server

[root@192.168.0.1 ~]# mkdir -p /mnt/nfsshare

Step 6: Now add the shared directory on NFS main configuration file /etc/exports. 

[root@192.168.0.1 ~]# vi /etc/exports

/mnt/nfsshare 192.168.0.2(rw,sync,no_root_squash)

Here, 192.168.0.2 is the client server.

Step 7: Now export as follows to effect the configuration

[root@192.168.0.1 ~]# exportfs -a

Step 8: Restart the rpcbind and nfs services 

[root@192.168.0.1 ~]# /etc/init.d/rpcbind restart

[root@192.168.0.1 ~]# /etc/init.d/nfs restart

Client Side:

Make sure the NFS port 111 is allowed for client server, or else stop IPtables. But stopping of IPtables is not a good practice.

Step 9: Mount the shared directory which is exported on NFS server. 

[root@192.168.0.2 ~]# mount -t nfs 192.168.0.1:/nfsshare /mnt/nfsshare/

 

Step 10: Now check the mounted partition with below command

[root@192.168.0.2 ~]# df -h

 

Step 9 is for only temporary mount. If you reboot the system it goes off. So, to mount it back automatically after the reboot also, then follow up below steps.

Step 11:  Open the fstab file and add below line 

[root@192.168.0.2 ~]# vi /etc/fstab

192.168.198.133:/nfsshare /mnt/nfsshare/         nfs     defaults        0 0

Save the file and exit

Now test the fstab configuration properly before reboot the server. Cause if there is any wrong entry, then the server will not start back

Try to unmount the share and mount it back as below

[root@192.168.0.2 ~]#  umount 192.168.198.133:/nfsshare

[root@192.168.0.2 ~]# mount -a

If it mounts back properly then fstab works properly after the reboot.

Test with reboot now.

 

 

 

 

Samba Configuration in Linux

Posted: January 13, 2016 in Uncategorized

This document is all about samba installation and configuration in Ubuntu.

Hopefully it works on Redhat/CentOS flavored OS as well.

Step 1: Install the samba package

apt-get install samba

Step 2: Now add the user useradd sambauser, No need to create password as this is not to be ssh user. 

useradd sambauser

Step 3: Now create the password for the user created above

smbpasswd -a sambauser

Step 4: Create a shared directory

mkdir /home/sambauser/shared -p

Step 5: Change the ownership of the directory

chown -R sambauser:sambauser /home/sambauser/shared

Step 6: Give the permissions to the directory

chmod -R 775 /home/sambauser/shared

Step 7: Take the backup of samba configuration file before we start editing that.

cp /etc/samba/smb.conf /tmp/

Step 8: Open the smb.conf file and add the below lines

vi /etc/samba/smb.conf

[shared]

path = /home/sambauser/shared

valid users = sambauser

writable = yes

read only = no

In this case, only sambauser can access this directory( /home/sambauser/shared) no other can’t access unless enter the correct credentials of this directory

The above is for single user and single directory.  We can add additional users also to access one directory by 2 or more users

[shared]

path = /home/sambauser/shared

valid users = sambauser,user1,user2

writable = yes

read only = no

We can add one or more directories to provide the privileges to one or more user as below…

[shared]

path = /home/rajesh

valid users = rajesh

writable = yes

read only = no

As this way, we can create multiple directories and setup their own credentials

But, username and smbpassword have to be created to work on…