Thursday, June 27, 2013

Show GUI alert boxes on remote host

Show popup/alert box on other system :

Sometime you want to give just a message to your colleague, you do not want reply. 

If you do not want to send messages on terminal or chat-box, you can use alert box to display the message but you should be able to log into your colleague's system.



Requirements:
ssh should be installed on both systems.
You should be able to log into your colleague's system.

Steps:
Log into the Remote Host (your colleague's system) using ssh.
# ssh 192.168.xx.xx
where 192.168.xx.xx is IP of the Remote Host.
Run following command on his/her command line
# DISPLAY=:0 zenity --info --text="your-message-should-be-here"
If you want to give the title for the message box.
# DISPLAY=:0 zenity --title="your-title" --info --text="your-message-should-be-here"
If you would not use DISPLAY=:0 in your command, it would show a display error.
Gtk-WARNING **: cannot open display: 
If you open the display using -X in your ssh command like ssh -X 192.168.xx.xx and run the command without using  DISPLAY=:0, it opens the alert box but on your system. Your colleague would not be able to see this.
You have to set DISPLAY on remote host.


Wednesday, June 26, 2013

Track the users who are using sudo

List of users who are using sudo :

If you are root of the server and there are several users who are logged in to the server, you should know your user activities.

There can be some circumstances that you just can't disable sudo facility and the reason is not that you don't know how but you can't because you have to give the functionality to the users.

You must know that how to find number of users, current logged in users and all that stuff.

But some of your user can misuse the sudo facility. You should track the record that  who are currently using sudo.

Fortunately Linux can track the record for you. To read this log file, you can know the list of the users who are using sudo.

If you are using Debian or ubuntu, the location of the file is
/var/log/auth.log

If you are using CentOS, Fedora or RHEL, the location of the file is
/var/log/secure

If user tries to remove his/her entry from the file, it enters this act in the file too so you can know that user has edited the log file and he has done something nasty.


Add one file's contents in other file on Remote host using command line

Add one file's text in another file on remote host :

If you have a file A and you want to add this whole file's text in file B but the problem is file B is on remote host.

You may be think to download the file B, update it and upload it again.

But you can do this using command line in a single command.

Suppose file A which is on your system is in  /root directory and file B which is on Remote host is in /root/Documents.

Now run following commands to add file A's text in file B.
# cat /root/fileA.txt | ssh 192.168.xx.xx "cat >> /root/Documents/fileB.txt"
or
# ssh 192.168.xx.xx "cat >> /root/Documents/fileB.txt" </root/fileA.txt
or
# scp /root/fileA.txt 192.168.xx.xx: /root/fileA.txt && ssh 192.168.xx.xx "cat /root/fileA.txt >>  /root/Documents/fileB.txt"
where:
192.168.xx.xx is IP of Remote Host

The commands do not remove the text of fileB instead they add the text at bottom of the fileB.