RSS Subscription
Linux Howtos & Tutorials

Enter your email:

Delivered by


NOTE:New tutorials are from LinuxCareer.com

Poll

Do you own or wish to have iPhone?
 


Linux eBooks FREE Download
A guide to programming Linux kernel modules
Introduction to Linux - A Hands on Guide
A Newbie's Getting Started Guide to Linux

Linux from Scratch - Create Your Own Linux System - Free eBook

Linux: The Hacking Solution (v.3.0)

SQLite 3 with PHP Essential Training – Free Video Training Tutorials

This guide will introduce you to the world of GNU/Linux

The GNU/Linux Advanced Administration

A Complete Beginner's Manual for Ubuntu 10.04 (Lucid Lynx)

Advanced Bash-Scripting Guide

Set up, maintain, and secure a small office email server

Partner Linux Sites:
How-To.LinuxCareer.com
Jobs.LinuxCareer.com
TuxMachines
Monsterb
LinuxBloggers
AdamsInfo
LinuxScrew
All For Linux

Limit user environment with ulimit Linux command

Whether it is user intention or just accident it may happen, that a single user can eat up all available system resources such as RAM memory or disk space. Depends on the nature of you Linux system you may want to limit your users to only what they might actually need.

Let's start with something like a fork bomb:

:(){ :|:& };:

The line above can almost instantly consume all resources since it creates recursive function all to it self as it forks unlimited children processes. One does not even need a root privileges to crash your Linux system. What about to limit user by a number of process he/she can spawn:

NOTE: All limits are applied to a current shell session only. To make a permanent change system wide use /etc/profile .

$ ulimit -u 10
$ :(){ :|:& };:
bash: fork: retry: Resource temporarily unavailable

This takes care of the fork bomb problem. But what about disk space? Linux command ulimit can limit users to create files bigger than a certain size:

$ ulimit -f 100
$ cat /dev/zero > file
File size limit exceeded (core dumped)
$ ls -lh file
-rw-rw-r--. 1 linux commands 100K Feb 21 18:27 file 

Some extreme examples:

With ulimit it is also possible to limit a maximum amount of virtual memory available to the process:

ulimit -v 1000
[lilo@localhost ~]$ ls
ls: error while loading shared libraries: libc.so.6: failed to map segment from shared object: Cannot allocate memory

Limit a user by number of opened files ( file descriptors )

$ ulimit -n 0
$ echo ulimit > command
bash: command: Too many open files

To check all your current limits use -a option:

$ ulimit -a

Share this linux post:

Submit Limit user environment with ulimit Linux command in Delicious Submit Limit user environment with ulimit Linux command in Digg Submit Limit user environment with ulimit Linux command in FaceBook Submit Limit user environment with ulimit Linux command in Google Bookmarks Submit Limit user environment with ulimit Linux command in Stumbleupon Submit Limit user environment with ulimit Linux command in Technorati Submit Limit user environment with ulimit Linux command in Twitter
 
Comments for this page are closed !!!
Please visit our new Linux Forum for additional help or discussion.


Linux eBooks FREE Download