Showing posts with label unix. Show all posts
Showing posts with label unix. Show all posts

Sunday, 9 December 2012

How to emulate a remote Linux machine on Mac using X11 port forwarding in ssh ?

Remote Linux server/machine can be accessed from Mac using X11 port forwarding feature in ssh.
X11, also known as X window system, is a combination of server and client programs which can be used to emulate desktop environment of remote Unix like machine on a local machine. The server program of X window system runs on local machine and the client program runs on remote machine.
The best feature of X11 window system is that it is separated into client and server program, which makes it suitable to use both the programs either on same machine or on different machines. For ex, when you are using a Linux desktop with GUI, both client and server programs are running on the same machine and when you access your remote unix like machine from local machine then the server program of X window system runs on local machine and the client program runs on remote machine.
Separation of client and server programs makes X window system really fast over networked connections as most of the drawing work is handled on the local machine.
X window system can be really complex to use over networked connection as server is on the local machine, which makes it difficult for the client, running at remote machine, to see the server.
ssh provides a feature to handle this complexity, which is known as X11 port forwarding.
X11 port forwarding feature of ssh makes a secure tunnel between client and server programs of X window system, so that they can communicate .
Now let's see how to use this feature of ssh to connect to a remote Linux machine from a Mac.
You need to have an X11 server program on your mac to connect to the remote Linux machine.
X11 app comes default with the Operating system for Snow Leopard users, but it has to be downloaded and installed explicitly on Mountain Lion.
Mountain Lion users can download X11 app from here.
Once app is installed, you will have to perform some configuration changes in ssh server running on remote Linux machine.

Add the following lines to the file /etc/ssh/ssh_config

ForwardAgent yes
ForwardX11 yes
ForwardX11Trusted yes

After this uncomment/add the following line in /etc/ssh/sshd_config file.

X11Forwarding yes

Restart the ssh server on remote machine for changes to take effect.
Now on local machine
Open terminal and execute the following command

ssh -X user@host.com

This will log you in to the remote machine if the keys are set, else, it will ask for password.
After you are logged in
Assuming that the remote machine's desktop environment is GNOME, execute the following 
command.

gnome-session

If everything works perfectly, you will be able to see your remote Linux machine GUI on your Mac.

For more info visit.

Sunday, 15 April 2012

Soft links(Symbolic links) in Unix.

Soft Links:-

We have seen hard links in our previous post. Hard links are nothing but more than one names for a file. Hard links have some shortcomings.

i) We cannot hard link two files in different file systems, i.e. a file in /usr directory cannot be hardlinked in /home directory.

ii) Hard links cannot link directories even in the same file systems. It can link only files.

Soft links remove limitations of Hard links.

Now let's see what are Soft links.

We make a file "file1" as shown below

[code]cat>file1
date
[/code]Assign execute permission to this file
[code]chmod u+x file1 [/code]
Now we create a symbolic link "file2" to this file as shown below
[code]ln -s file1 file2[/code]
Note: We are using -s attribute to create a symbolic link. If -s is not used then it would create a hard link.

Now, our symbolic link is created. You can verify the creation of symbolic link using

[code]ls -l file2[/code]
Output is:

lrwxr--r-- 1 user1 user1 2012-04-15 16:14 file2 -> file1

Note: l in the starting and "file2 -> file1" denote the creation of symbolic link. Also, number in the second column is 1. This means, a new file is created, as contrary to Hard links in which no new file is created.

Now we have two files. We know the content of file1 but What does file2 contains?

file2 contains the pathname of file1. When we execute cat command on file2, it actually redirects to file1 and opens its content.
So, cat file1 and cat file2, both show the same content. We can also execute the content using any of the file.

The output of ./file1 and ./file2 are same, i.e.

Sun Apr 15 16:18:28 EDT 2012

 One  advantage of soft link over hard link is that it can link directories also. Suppose we have to link a large number of files from one directory to another. If we use Hard link, then the only way is to link each file individually. But, when we use soft link, we can link an entire directory to another directory.

Caution: Hard link provides safety against accidental deletions, i.e. if one alias is deleted then we can access the file through other aliases.

But, in the case of symbolic link, we created above,  if file2 is deleted then there is nothing to worry about. But, if  by mistake file1 is deleted then all our content is lost.  Also symbolic link file2 would become a dangling symbolic link.This is because symbolic link is a seperate file, and  not a pointer to the original file.

 

For more information visit

Thursday, 12 April 2012

What is Sticky bit?

Sticky bit is used for advance level file permission in Unix. It is one of the twelve bits used in File security.  Generally, users know only about nine bits which are used in File permissions, i.e. 3 for user/owner, 3 for Group to which the file owner belongs and 3 for others. There are 3 other bits also used for advance level file permissions

i) SUID bit

ii) SGID bit

iii) Sticky bit

I already explained the use of SUID bit in this post.

Sticky bit can be used with files, as well as directories. Sticky bit is rarely used with files these days. The main use of Sticky bit comes when it is used with directories.

Sticky bit with files

Sticky bit is used with files in order to make it persist in the swap area or memory. In earlier days when RAM was limited in size, the scheduler used to swap programs very swiftly from RAM to Hard drive. This would cause problems when the part of the program was used very frequently in some process. So, what the programmer would do. He used to set sticky bit on files which were used very frequently, in order to retain them in the memory.

Now a days we have RAM of very high capacities, so Sticky bit is rarely used on files.

Sticky bit with directories

The main use of sticky bit is with directories. For understanding this, we will have to understand  file permissions on directories.

Suppose there is a public directory,  "pubdir" , which has permissions like following

rwxrwxrwx

Since it is  a public directory, it has executable and write permissions for everyone. Now suppose, I have a file "myfile" which is in this public directory , and I have given it permission like following

rwxr- -r- -

I have not given write or execute permission to others. This means that any other user will not be able to edit or execute my file. But will heshe able to delete my file? Well that depends on the directory permissions in which my file is residing.

Now, let's understand "pubdir" directory permissions.

i) Everyone has read permission: Everyone will be able to see the contents of this directory using   ls -l.

ii) Everyone has execute permission: Everyone will be able to access the directory, access on a directory means, anyone can go inside directory using cd command.

iii) Everyone has write permission: Anyone will be able to edit/delete any of the contents of directory.

Now, what are the contents of a directory?...........wwwoooooo  FFFFFFFFiiiiiiiilllllllllleeeeeeeeeeessssssssss.

Damn it. All the files, owned by any user, are vulnerable to a lot of threats.

Now you understood the problem.

Don't worry, we have a solution in the form of Sticky bit. When we set sticky bit for a directory then it puts a restriction on the directory that only the file owner of the file, which is inside the directory, will be able to delete it, and not anyone else.

Sticky bit can be set in the following way.

chmod +t filename

After setting the sticky bit, the directory permission would look like

rwxrwxrwt

The most practical use of sticky bit is in /var/temp. temp directory is public and common to every user.

For more information visit