Showing posts with label LINUX. Show all posts
Showing posts with label LINUX. Show all posts

Friday, September 23, 2011

Share file & folders in Ubuntu with NFS


NFS stands for (take a guess…) Network File System. NFS is a protocol developed by Sun Microsystems in 1984 to allow computers to share files and folders over a network. NFS is an open standard, defined in RFCs, and allows any to implement the protocol.
Although many prefer to employ Samba for network folder sharing, NFS still has a lot of good uses and some even prefer it over the more flexible Samba.

Installation

Both client and server will need the package nfs-common. On the server machine you will need to install the package nfs-kernel-server. To install these packages follow these steps:
  1. Open up Synaptic (or your favorite Add/Remove Program utility).
  2. Search for “nfs” (no quotes).
  3. Mark nfs-common (for the client) and nsf-common and nfs-kernel-server (for the server).
  4. Click Apply to install.
In Command line Mode, You used :
# apt-get update
# apt-get install nfs-common nfs-kernel-server
That’s it. Now it’s time for a little configuration.

Configuration

For example’s sake, the two machines we are using are addressed as such:
Server: 192.168.1.100
Client: 192.168.1.10
On the client we will create a directory which the NFS server share will mounted to. We’ll create the folder ~/UBUNTU_NFS with the command mkdir ~/UBUNTU_NFS. Now let’s move over to the server.
The first thing to be done on the server machine is to create folder that will be shared out. Let’s call that folder ~/SHARE and we’ll create it with the command mkdir ~/SHARE.
Now we have to create an entry in the /etc/exports folder. This entry will tell NFS what to share and who to share with. The entry will look like:
/home/USERNAME/SHARE     192.168.1.10(rw)
Where USERNAME is the actual name of the user. NOTE: You could share a folder in /opt if you like.
Now nfs-kernel-server has to be restarted with the command:
# /etc/init.d/nfs-kernel-server restart

Mounting

Hop back on to the client machine and issue the command:
#  mount 192.168.1.100:/home/USER/SHARE /home/USER/UBUNTU_NFS
Where USER is the actual user name.
You should get no errors. Now let’s test this out. Hop on back to the server and create a file within ~/SHARE. After you create that file, check the ~/UBUNTU_NFS directory on the client to make sure the file shows up. Try to delete that file. Now create a file in the ~/UBUNTU_NFS directory on the client. You should have no problems creating a file.

Automounting

Say you want this share to always be mounted upon boot of the client machine. This, of course would require the server machine to be on. To do this add an entry on the client machine’s /etc/fstab that looks like:
192.168.1.100:/home/jlwallen/ELIVE  /home/jlwallen/UBUNTU  nfs rsize=1024,wsize=1024,noauto 0 0
NOTE: The above fstab entry is all one line.
Now that NFS share will mount even when the machine is rebooted.
As you can see, NFS has become much easier than it was in the old days. Now, armed with NFS and Samba, you can be sharing files and folders with anyone and everyone.

Access Samba share (Windows share file & folder ) in Linux


First I am going to assume you have your Samba server set up and you are able to connect to it from other machines. Outside of that you will need only one piece of software installed on your Linux machine: smbclient. This will be in your distributions’ repositories so just open up your Add/Remove Software utility, search for smbclient, select it, and click Apply.
Or used command :
# apt-get install smbclient ( in ubuntu/debian)
# yum install smbclient ( in fedora/centos )
Once smbclient is installed you are ready to go.
Let’s first test to make sure your Linux box can see the Samba share. You will need either sudo or root access to do this. Issue the command:
# smbclient //IP_TO_SAMBA_SERVER/SHARE_NAME -U USERNAME
Where:
IP_TO_SAMBA_SERVER is the IP address of your Samba server.
SHARE_NAME is the share you want to connect to.
USERNAME is the user name you connect to the share with.
If all is well you should see something like this:
Enter wallenmusic’s password:
Domain=[MONKEYPANTZ] OS=[Unix] Server=[Samba 3.2.5]
smb: \>
If you see that you can type quit and then hit the Enter key to escape this prompt.

Setup

The first thing you need to do is create a directory to mount the Samba share to. I created the directory /data with the command:
# mkdir /data
Once that directory is created you can then mount it with the command:
# mount -t smbfs -o username=USERNAME //IP_TO_SAMBA_SERVER/SAMBA_SHARE /data
Where:
IP_TO_SAMBA_SERVER is the IP address of your Samba server.
SHARE_NAME is the share you want to connect to.
USERNAME is the user name you connect to the share with.
Now if you check the /data directory you should see a listing of the contents of the Samba share.

Automount

Let’s make that share automount at boot. This will require editing your /etc/fstab file, adding an entry for this Samba share. In this file (again you will have to have either root or sudo access) you will add a line like this:
//IP_TO_SAMBA_SERVER/SAMBA_SHARE� /data smbfs username=USERNAME,password=PASSWORD, 0 0
Where:
IP_TO_SAMBA_SERVER is the IP address of your Samba server.
SHARE_NAME is the share you want to connect to.
USERNAME is the user name you connect to the share with.
PASSWORD is the password for the Samba user
Once that entry is saved unmount the /data directory with the command:
# umount /data
so you can test your automount entry.
Now, enter the command:
# mount -a
 If there are no errors you should see the contents of the Samba share in the /data directory.  That’s it. Congratulations, you now have an automounted Samba share on your Linux machine.

Limit User & IP access SSH


There are several worms which attempt to exploit vulnerable SSH servers, by logging in to a host with a collection of usernames and passwords such as “admin/admin”, “test/test”, “root/root”, etc. These shouldn’t be of much concern if you’re keeping good passwords, but there are simple ways to prevent them regardless.
The most obvious way to prevent people connecting to your host is to only allow connections from small number of IP addresses, by the use of a firewall.
If you’re currently running a firewall you can add to it to :
Accept incoming SSH connections from a trusted address.
Drop all other connections.
Using the iptables firewall commands you can do this as follows:
All connectsion from address 1.2.3.4 to SSH (port 22) :
# iptables -A INPUT -p tcp -m state –state NEW –source 1.2.3.4 –dport 22 -j ACCEPT
Deny all other SSH connections
# iptables -A INPUT -p tcp –dport 22 -j DROP
If you’re not running a firewall, or you don’t wish to mess with the setup you can look at another way of restricting access. The Debian packages of openSSH are compiled with tcpwrappers support, which means you can specify which hosts are allowed to connect without touching your firewall.
The two important files are:
/etc/hosts.allow
/etc/hosts.deny
The first can contain entries of hosts which are allowed to connect, the second contains addresses which are blocked.
Assuming that you wish to allow the remote addresses 1.2.3.x, and 192.168.0.x to connect but nothing else you would setup the files as follows. Firstly allow access by placing the following inside /etc/hosts.allow:
# /etc/hosts.allow
sshd: 1.2.3.0/255.255.255.0
sshd: 192.168.0.0/255.255.255.0
Then disallow all further access by placing this in /etc/hosts.deny:
# /etc/hosts.deny
sshd: ALL
Finally you can look at the ssh configuration itself, this has several useful security options you can enable.
The ssh server is configured by the file /etc/ssh/sshd_config. If you wish you can restrict remote access to specific users.
For example to only allow “mark” and “paul” to login add the following:
AllowUsers mark  paul
With this setting in place (after the server has been restarted with “/etc/init.d/ssh restart”) all other users will be unable to connect via SSH even if they login with the correct username and password.
You can also explicitly deny particular users:
DenyUsers jonh  andrew
Probably the most important setting you can change in the sshd_config file is the following:
PermitRootLogin no

With this setting set to “no” remote root logins are denied.