Friday, July 20, 2012

Linux useful command

Redirect output:
< file means open a file for reading and associate with STDIN.
<< token Means use the current input stream as STDIN for the program until token is seen. We will ignore this one until we get to scripting.
> file means open a file for writing and truncate it and associate it with STDOUT.
>> file means open a file for writing and seek to the end and associate it with STDOUT. This is how you append to a file using a redirect.
n>&m means redirect FD n to the same places as FD m. Eg, 2>&1 means send STDERR to the same place that STDOUT is going to.


/etc/sudoers Syntax

To fully explain the syntax of /etc/sudoers, we will use a sample rule and break down each column:
jorge  ALL=(root) /usr/bin/find, /bin/rm
The first column defines what user or group this sudo rule applies to. In this case, it is the user jorge. If the word in this column is preceded by a % symbol, it designates this value as a group instead of a user, since a system can have users and groups with the same name.
The second value (ALL) defines what hosts this sudo rule applies to. This column is most useful when you deploy a sudoenvironment across multiple systems. For a desktop Ubuntu system, or a system where you don't plan on deploying thesudo roles to multiple systems, you can feel free to leave this value set to ALL, which is a wildcard that matches all hosts.
The third value is set in parentheses and defines what user or users the user in the first column can execute a command as. This value is set to root, which means that jorge will be allowed to execute the commands specified in the last column as the root user. This value can also be set to the ALL wildcard, which would allow jorge to run the commands as any user on the system.
The last value (/usr/bin/find, /bin/rm) is a comma-separated list of commands the user in the first column can run as the user(s) in the third column. In this case, we're allowing jorge to run find and rm as root. This value can also be set to the ALL wildcard, which would allow jorge to run all commands on the system as root.

Make ISO image

We’re going to use the command line tool dd tool for this. Insert the disc that you want to copy and open a terminal.

Create a cdrom image

Now in the terminal type:


1
sudo dd if=/dev/cdrom of=cd.iso

A little explanation
  • sudo makes sure the command is executed as root. That’s needed only if the user you’re working under doesn’t have enough permissions to access the device. But it’s ignored if it’s not needed so you can just ignore it as well.
  • dd stands for Disk Dump
  • if stands for Input File
  • of stands for Output File
Wait for the command to finish, and your new iso will be saved to cd.iso.

Create a dvd image

For a DVD image, your device is probably called /dev/dvd instead of /dev/cdrom so the command would look like this:


1
sudo dd if=/dev/dvd of=dvd.iso

Create a scsi cdrom image

For a SCSI CDROM image, your device is probably called /dev/scd0 instead of /dev/cdrom so the command would look like this:


1
sudo dd if=/dev/scd0 of=cd.iso

Mounting an image

Once you’ve created an ISO image you can mount it as if it was a normal disc device (loopback) device. This will give you access to the files in the ISO without you having to burn it to a disc first. For example if you wanted to mount cd.iso to /mnt/isoimage you would run the following commands:


1
2
3
mkdir -p /mnt/isoimage

mount -o loop -t iso9660 cd.iso /mnt/isoimage

Unmounting

To unmount a currently mounted volume, type:


1
umount -lf /mnt/isoimage

/mnt/isoimage is the location of your mounted volume.

Force Mac OS Lion create new account
mount -uw/
rm /var/db/.AppleSetupDone
shutdown -r now

Mount Directory
vi /etc/fstab

Add below line
/var/www/html/test   /home/test/test          none        bind     0 0  

Sudoers
You can take a command out of a sudo account by using the ! (not operator) for example to let bill use all commands except su, shutdown, halt and poweroff the line would look like (in /etc/sudoers)

Code:
bill        ALL = (ALL) ALL !su !shutdown !halt !poweroff
this does not seem like a good idea as there may be ways around the exact command. such as using a shell escape from another program.

You can give access to directorys just like you can command. for example if you wanted bill,mike,pete and members of the project group to be able to access /path/to/project/*. you'd use 

Code:
User_Alias     THISGROUP = bill, mike, pete

THISGROUP, %project ALL= /path/to/project/*
the user alias statement should be near the top all other statements should be with the main body of statements in sudoers file

No comments: