303.2 File Share Security (weight: 3)

Tech Tutorial: 303.2 File Share Security (weight: 3) #

Introduction #

In this tutorial, we will delve into the management of file permissions on both Linux file systems and CIFS (Common Internet File System) shares. Understanding file permissions is crucial for securing data and ensuring that only authorized users and systems have access to specific files.

Key Knowledge Areas #

  • Understanding Linux file permissions
  • Managing CIFS file share permissions
  • Utilizing command-line tools to set and view permissions

Utilities #

  • chmod
  • chown
  • ls
  • getfacl
  • setfacl
  • smbclient
  • mount.cifs

Step-by-Step Guide #

Linux File Permissions #

Viewing Permissions #

To view the permissions of files and directories in Linux, we use the ls command with the -l option:

ls -l filename

Example:

$ ls -l myfile.txt
-rw-r--r-- 1 user group 0 Sep 29 12:00 myfile.txt

This output shows that myfile.txt is readable and writable by the owner (user), readable by the group (group), and readable by others.

Changing Ownership #

The chown command is used to change the owner and group of a file:

chown newowner:newgroup filename

Example:

$ chown alice:staff myfile.txt

Modifying Permissions #

The chmod command changes the file modes or Access Control Lists (ACLs). Here’s how you can give the owner execute permissions:

chmod u+x filename

Example:

$ chmod u+x myfile.txt

To set specific permissions using numeric mode:

chmod 755 filename

Example:

$ chmod 755 myfile.txt

Advanced Permissions with ACLs #

Viewing ACLs #

ACLs provide more granular permissions. To view the ACLs:

getfacl filename

Example:

$ getfacl myfile.txt
# file: myfile.txt
# owner: alice
# group: staff
user::rw-
group::r--
other::r--

Setting ACLs #

To grant specific users or groups permissions:

setfacl -m u:username:rwx filename

Example:

$ setfacl -m u:bob:rwx myfile.txt

Managing CIFS Shares #

Using smbclient to Access Shares #

To list available shares on a server:

smbclient -L //servername -U username

Example:

$ smbclient -L //192.168.1.100 -U alice

Mounting CIFS Shares #

To mount a CIFS share on a Linux system, use mount.cifs:

sudo mount.cifs //servername/sharename /mnt/share -o user=username

Example:

$ sudo mount.cifs //192.168.1.100/data /mnt/data -o user=alice

Conclusion #

In this tutorial, we covered essential aspects of managing file permissions on Linux file systems and CIFS shares. By understanding and applying these concepts, you can effectively secure data accesses in a multi-user or networked environment. Always ensure to test permissions settings in a safe testing environment before applying them in production to avoid accidental data exposure or loss.


This comprehensive guide should equip you with the knowledge to handle file permissions adeptly on both local Linux systems and network CIFS shares, helping you secure your systems in line with best practices.