Results 1 to 7 of 7
Hi
i am totally new to this forum as well as linux...
as per my knowledge by using "ulimit" we can restrict the size of file that can create by ...
- 02-04-2008 #1Just Joined!
- Join Date
- Feb 2008
- Posts
- 8
regarding command "ulimit"
Hi
i am totally new to this forum as well as linux...
as per my knowledge by using "ulimit" we can restrict the size of file that can create by user.
but in one folder i make the ulimit as 1kb by "ulimit -f 1"
but still i can create the file with more than 1kb ..
i need completely user need to prevent for creating file in the particular folder
[sorry for bad english]
- 02-04-2008 #2Linux Enthusiast
- Join Date
- Apr 2004
- Location
- UK
- Posts
- 658
If you need to prevent a user from creating files in a directory, then you should use chmod rather than ulimit.
The permissions in the first column of the 'ls' command are Read, Write and eXecute. If I use chmod to remove the write permission on the directory then I can no longer create files there.Code:chris@angua:~$ mkdir test chris@angua:~$ ls -la test total 8 drwxr-xr-x 2 chris chris 4096 2008-02-04 13:56 . drwx------ 84 chris chris 4096 2008-02-04 13:56 .. chris@angua:~$ touch test/file1 chris@angua:~$ ls -la test total 8 drwxr-xr-x 2 chris chris 4096 2008-02-04 13:56 . drwx------ 84 chris chris 4096 2008-02-04 13:56 .. -rw-r--r-- 1 chris chris 0 2008-02-04 13:56 file1 chris@angua:~$ chmod 500 test chris@angua:~$ ls -la test total 8 dr-x------ 2 chris chris 4096 2008-02-04 13:56 . drwx------ 84 chris chris 4096 2008-02-04 13:56 .. -rw-r--r-- 1 chris chris 0 2008-02-04 13:56 file1 chris@angua:~$ touch test/file2 touch: cannot touch `test/file2': Permission denied chris@angua:~$
In this example I keep ownership of the test directory. This means I can change the permissions to allow me to write files again. To prevent this I would need to change ownership of the directory to another user. Use 'chown' to do that.
Let us know how you get on,
Chris...To be good, you must first be bad. "Newbie" is a rank, not a slight.
- 02-05-2008 #3Just Joined!
- Join Date
- Feb 2008
- Posts
- 8
thanx buddy
but it is not happening here...
NB: am entered as "root" user
- 02-05-2008 #4Linux Enthusiast
- Join Date
- Apr 2004
- Location
- UK
- Posts
- 658
Trying to prevent a root user from doing whatever they please is usually a waste of time. There are such things as SELinux which you may be able to use but I've never tried them.
A more practical way is to remove the need to be root in order to do what you are trying to achieve. If root access is required for a part of the task then sudo can be used to allow normal users to perform specific tasks as root.
Can you tell us more about what you are trying to do. Then we may be able to help you find a simple way to do it.
Let us know how you get on,
Chris...To be good, you must first be bad. "Newbie" is a rank, not a slight.
- 02-05-2008 #5Just Joined!
- Join Date
- Feb 2008
- Posts
- 8
ok i will explain..
am testing a tool that only works in "root" user
the tool is creating one file in some folder...
i need to check what will happen if tool try to generate a file in to a folder..
where no permission or any other similiar conditions..
i heard by using ulimit we can restrict the size of file...
but still tool succesfully generated file..
- 02-05-2008 #6Linux Enthusiast
- Join Date
- Apr 2004
- Location
- UK
- Posts
- 658
You may already have your answer: If you are root you can ignore permissions for the most part and I would guess that is why ulimit isn't working either.
One way to actually have this fail would be to make a small read only filesystem and try to write your file there.
Note the "-o ro" option on mount sets the filesystem to read only. The root user can still work around that so don't rely on it, but it should fail for now.Code:chris@angua:~/src$ sudo -s [sudo] password for chris: root@angua:~/src# cd root@angua:~# dd if=/dev/zero of=./disk.img bs=1024 count=1024 1024+0 records in 1024+0 records out 1048576 bytes (1.0 MB) copied, 0.00394552 seconds, 266 MB/s root@angua:~# losetup /dev/loop0 ./disk.img root@angua:~# mkfs.ext2 /dev/loop0 mke2fs 1.40.2 (12-Jul-2007) Filesystem label= OS type: Linux Block size=1024 (log=0) Fragment size=1024 (log=0) 128 inodes, 1024 blocks 51 blocks (4.98%) reserved for the super user First data block=1 Maximum filesystem blocks=1048576 1 block group 8192 blocks per group, 8192 fragments per group 128 inodes per group Writing inode tables: done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 28 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. root@angua:~# mkdir /mnt/test root@angua:~# mount /dev/loop0 /mnt/test -o ro root@angua:~# touch /mnt/test/file1 touch: cannot touch `/mnt/test/file1': Read-only file system root@angua:~# umount /mnt/test root@angua:~# losetup -d /dev/loop0 root@angua:~# rm disk.img
Let us know how you get on,
Chris...To be good, you must first be bad. "Newbie" is a rank, not a slight.
- 02-06-2008 #7Just Joined!
- Join Date
- Feb 2008
- Posts
- 8
i solved my problem by "ulimit" it self
actually i didnt know about the fact that "ulimit" will only in that particular session.
i set the ulimit
then run the tool from the same session
tool is crashing......


Reply With Quote