≡ Menu

chmod command

I'm CentOS Linux version 5.x user and I'd like to restrict execution of /usr/sbin/userhelper to console users only in xusers group?
[click to continue…]

Q. I've couple of remote servers and I'd like to access few admin only application running on port 10000 and 3001. My firewall only allows port 80, 443, 25, 22 and 110 for public access. Do I need to open port 10000 and 3001 for everyone using firewall? How do I access my admin only apps without opening port 10000 and 3001?
[click to continue…]

HowTo: Run the .sh File Shell Script In Linux / UNIX

I've downloaded a software for Linux from the Internet. There is a file called install.sh. How do I run an .sh file to install the software?
[click to continue…]

I've written a PHP script. I would like to run it as a cron job. I'm using CentOS server with Apache web server. How do I setup a PHP script as a cron job on a Linux or Unix-like systems?
[click to continue…]

Can you provide more information about chmod command octal mode number notation?
[click to continue…]

Howto: Linux Write protect a file

Q. How do I write protect a file under Linux? I’m using CentOS 5 server Linux operating system. I need prevent accidental changes to my files.

A. There are two ways to write protect a file under Linux.

Method #1: You can make file readonly by removing users’ write permission for a file. Under Linux and UNIX user cannot remove or modify file if they don’t have a write permission. You can use normal chmod command for this purpose.

Method #2 : You need to use chattr command which changes the file attributes on a Linux second extended (ext2 / ext3) file system. You need to setup i attribute. A file with the i attribute cannot be modified: it cannot be deleted or renamed, no link can be created to this file and no data can be written to the file. Only the superuser (root) or a process possessing the CAP_LINUX_IMMUTABLE capability can set or clear this attribute.

Write protecting a file using chmod command

Let say you want to write protect the file called data.txt so that no other users can change it, enter:
$ chmod go-w data.txt
To provide back permission use:
$ chmod go+w data.txt

Write protecting a file using chattr command

Let say you want to write protect the file called data.txt so that no other users can change it including root user, enter (you must login as the root user to use chattr command):
# chattr +i data.txt
To remove i attribute, enter:
# chattr -i data.txt

How do I recursively change files with 777 permissions to 755 in /home/user/demo directory? I have a number of files in this directory and I need to change permission from 0777 to only if that file has 777 permissions. Is there an easy way out to achieve this on a Linux or Unix-like systems?
[click to continue…]