Protect Single User Mode And More

  • How to protect single user mode (init 1) in Red Hat linux?
  • How to Kernel compile ?
  • Restrict user login based on time and terminal ?
  • How to Manage Write CD Images in Linux?
  • Specify Download Speed / Download Rate Using wget limit-rate
  • Finding total size of files owned by a particular user
  • Finding all large files in the root filesystem

How to protect single user mode (init 1) in Red Hat linux?

To protect this:-

# vi /etc/inittab

#add this line

su:S:wait:/sbin/sulogin

#save and exit

#init 1

here you prompt for password.

How to Kernel compile ?

# make config

or

# make menuconfig

or

# make xconfig <– Basen on QT in 2.6.x

or

# make gconfig

# make dep

# make bzImage

copy this bzImage into /boot/ and create new initrd (mkinitrd command) file . after this modify grub.conf file then restart.

Restrict user login based on time and terminal ?

#vi /etc/security/time.conf

A simple /etc/security/time.conf file will look like:

*;tty1;jim;A10000-2300

login & ssh;*;jane | jim|bill|susan;A11200-2000

ftp;*;guest;MoTuFr0800-1700&!Wk0000-2400

finger;*;guestA10000-2400

Now, let’s examine the contents of this file. The first line:

*;tty1;jim;A10000-2300

allows the user Jim access to all services from midnight until 11:00 P.M., as long as Jim is logging from tty1.

The second line:

login & ssh;*;jane | jim|bill|susan;A11200-2000

allows the users Jane, Jim, Bill, and Susan access to the system on any day of the week from 12:00 noon until 8:00 P.M. as long as they are accessing the system using /bin/login, or the secure shell, ssh.

The third line:

ftp; *;guest;Wk0000-2400

allows the user guest access to the system via FTP at any time during the weekend.

The last line:

finger;*;guestA10000-2400

prevents the user from obtaining finger information from the system at any time.

Test yourself What would happen if I placed the following entry in /etc/security/time.conf?

*;*;*;!A10000-2400

If you guessed that this entry would deny access to all users, including root, you’re right. The point here is to be very careful when making modifications to the time.conf file. Always make a backup copy of this file before any modifications are made.

How to Manage Write CD Images in Linux?

create ISO image of cd data

# dd if=/dev/cdrom of=/home/abc/image.iso

mount this ISO image file in local

# mount -o loop -t iso9660 /home/abc/image.iso /xyz

Burning an .iso file works with the following command:

# cdrecord -v dev=0,0,0 /home/abc/image.iso

How to auto logout with terminal in Linux?

# vi /etc/bashrc

– in bottom of file write this line

TMOUT=20 # time in second

– then save and logout

Specify Download Speed / Download Rate Using wget limit-rate

$ wget –limit-rate=200k http://www.openss7.org/repos/tarballs/strx25-0.9.2.1.tar.bz2

Finding total size of files owned by a particular user

Example:

Foldername to search: /my-path

Username: user1

# find /my-path -user user1 -ls | awk ‘{sum += $7} END {printf “Total size: %8.4f MB\n”, sum/1024/1024}’

To find the last modified files in a directory you can use ls -ltr. To find the last modified file on a file system it will not work, but the following command will work:

#find /etc -type f -printf “%T@ %T+ %p” | sort -n

Unmount busy drives

You are probably all too familiar with the situation – you are trying to unmount a drive, but keep getting told by your system that it’s busy. But what application is tying it up? A quick one-liner will tell you:

$lsof +D /mnt/windows

This will return the command and process ID of any tasks currently accessing the /mnt/windows directory. You can then locate them, or use the kill command to finish them off.

Stat command can be used either to check the status/properties of a single file or the filesystem.

[root@feenix ~]# stat inventry.sh

File: `inventry.sh’

Size: 2721 Blocks: 8 IO Block: 4096 regular file

Device: 302h/770d Inode: 2046099 Links: 1

Access: (0755/-rwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root)

Access: 2012-05-05 16:15:58.000000000 +0530

Modify: 2012-05-05 08:39:41.000000000 +0530

Change: 2012-05-05 08:39:41.000000000 +0530

Finding all large files in the root filesystem

I have a linux server, which currently has below space usage:

/dev/sda3 20G 15G 4.2G 78% /

/dev/sda6 68G 42G 23G 65% /data

/dev/sda2 30G 7.4G 21G 27% /opt

/dev/sda1 99M 19M 76M 20% /boot

tmpfs 48G 8.2G 39G 18% /dev/shm

As you can see. / is at 78%. I want to check, which files or folders are consuming space.

I tried this:

find . -type d -size +100M

Which shows result like this:

./data/app/june01.dbf

./data/app/temp01.dbf

./data/app/smprd501.dbf

./home/feenixdv/centos.iso

./home/feenixdv/filegroup128.jar

Now this is my issue. I only want the name of those files located in folders that are consuming space at / and not at /data or /home. Since / is base of everything, it is showing me every file of my server.

Is is possible to get big files that is contributing to 78% of / ?

Answers:-

 find / -xdev -type f -size +100M

Leave a Reply

Your email address will not be published. Required fields are marked *