Showing posts with label linux command. Show all posts
Showing posts with label linux command. Show all posts

Friday, 6 September 2013

Strace : Moniter system calls

Leave a Comment

Introduction

Strace is a small useful debugging tool which traces all the system calls and signals used by  the program. Internally Strace uses ptrace system call to trace the system calls executed by the program. This list of system calls is useful to get clear idea, how program is interacting with the kernel.

Installation:

In Ubuntu you can install Strace using 
sudo apt-get install strace
In CentOS you can install by
yum install strace

OR 
Download the Strace-4.8.tar.xz
tar xvJf strace-4.8.tar.xz
cd strace-4.8/
./configure
make
make install        (as root or sudoer user)

Use: 

  1. strace who        (Default it will print all the system call and signals)
    execve("/usr/bin/who", ["who"], [/* 42 vars */]) = 0
    brk(0)                                 = 0x1568000
    access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
    mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f2e366b1000
    access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
    open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
    ..
    ..
  2. strace -o output.txt who (-o is used to write the result of strace utility in the file)
    strace who > output.txt
    This will write the result of executing command here it is who, in the output.txt file not the system calls that are traced by the strace command.
  3. strace -c who (-c is used to calculate total number of times the system call is appeared without giving the details of each system call)
  4. strace -C who (-C is used to calculate total number of times the system call is appeared with giving the details of each system call)
  5. strace -e write who (-e option is used to detect specific system calls provided out of all)
    write(1, "krishna  tty7         2013-09-06"..., 44krishna  tty7         2013-09-06 09:36 (:0)
    ) = 44
    write(1, "krishna  pts/0        2013-09-06"..., 46krishna  pts/0        2013-09-06 12:47 (:0.0)
    ) = 46
    write(1, "krishna  pts/1        2013-09-06"..., 46krishna  pts/1        2013-09-06 11:54 (:0.0)
    ) = 46
    +++ exited with 0 +++

    strace -e trace=read,write who (We can use this command to detect multiple system calls as we have perform above example for only one)
  6. We can also get the traces of currently running (executing) process
    strace -p 2700 (here 2700 is the process id of the currently running job)
Read More...

Tuesday, 11 June 2013

No valid sudoers sources found quitting ubuntu

1 comment
This error happen due to change in permission of sudoers file.
Pkexec command is used to execute command as another user. Older versions of Ubuntu don't support this command. If you are able to use pkexec command then you are not require to reboot and go to recovery mode use following commands

pkexec chown -R root:root /etc/sudoers.d
pkexec chmod u=rwx,g=rx,o=rx /etc/sudoers.d/
pkexec chmod u=r,g=r,o= /etc/sudoers.d/*


If you are running on old versions which could not support pkexec then you require to use recovery mode.
You can go into recovery mode by selecting grub menu ending with recovery mode option ->root -> give root password
after this enter command

fdisk -l (gives all detail disk partition)

Since in ubuntu recovery mode is read only you will require to remount in read-write mode using following command

mount -o remount,rw /dev/sda(drive containing installation i.e root)
now enter above commands without pkexec as below

chown -R root:root /etc/sudoers.d
chmod u=rwx,g=rx,o=rx /etc/sudoers.d/
chmod u=r,g=r,o= /etc/sudoers.d/*


now reboot and you will be able to use sudo or su command

Read More...

Friday, 3 May 2013

Secure CoPy (SCP)- Secure Option to Copy Files in Linux

8 comments

 

1. What is Secure CoPy (SCP) ?

            SCP is a command used to transfer files or folders securely to a particular remote user. In windows sharing of folders or files can be done in LAN only. There is no facility provided to transfer data securely from one user to another remote user, we require to use service from some third party software to do so. In Windows you can get this facility by installing WinSCP software and transfer the files directly to the Linux OR you can install OpenSSH on Windows machine using cygwin which is a collection of tools which provide a Linux like environment for Windows operating system. After OpenSSH installation you can transfer files using SCP from Windows to Linux and from Linux to Windows.

2. How to Use SCP ?

           To use SCP, first you have to start ssh service on the other side where you want to transfer the data. To start the service in red hat based OS switch to root user and give the command as " service sshd start ", for debian based OS you can use " sudo /etc/init.d/ssh start " or " sudo service ssh start ". SCP requires password of the remote machine to copy files or folder, so you can keep ssh server running all time, no one can copy irrelevant material without prior authentication.
          After starting the ssh service of target system you can give following command to start copy.
Syntax to copy single file:
         scp file1.txt user@target_IP_Address:~/Destination_PATH 

Here, you require to provide user name with IP address of remote system as shown above. 
Here ~ is used to represent home directory of a particular user in Linux.
After entering this command you need to provide the password of the target system , if password is correct then your copying files get started.
To copy multiple files using SCP, you can give multiple file names separated by space. Files may have different extensions.

Syntax to copy multiple files:
          scp file.txt file2.avi file3.iso user@target_IP_Address:~/Desktop

To copy particular folder you can use SCP command with " -r " option which indicates recursive operation.

Syntax to copy single folder:
          scp -r folder_name user@target_IP_Address:~/Desktop


You can also copy multiple folders using SCP like we did with multiple files as given above. You can use following command to copy multiple folders using SCP command.

Syntax to copy multiple folders:
         scp -r folder1 folder2 user@target_IP_Address:~/Desktop 


3. Errors and solutions

  • One common error is " port 22: Connection refused " which occurs when ssh service of the destination machine is stopped. You can eliminate  this error by starting ssh service at the destination machine.
  • Another error is that your file or folder get copied to your own directory with user name followed with IP address like " user@target_IP_Address ". This error happens if " :PATH " is not mentioned in command.
Read More...

Tuesday, 30 April 2013

What is ssh ?

Leave a Comment

1. What is Secure SHell (SSH)

   SSH is a network protocol which uses public-key cryptography. SSH is more secure than rsh, telnet. Generally SSH is used to access remote machine using password authentication and to form cluster of different machines. You can also see GUI for file manager of remote system so that controlling becomes easier (nautilus for GNOME, krusader for KDE etc.). Generally in Linux, openssh provides SSH protocol. You can use PUTTY to act as SSH client for Windows OS. To install SSH server in windows you have to install CYGWIN. In Windows you can not get GUI through file manager as you do in Linux.
   CYGWIN is a collection of tools which provide a Linux-like environment for Windows operating system.

2. Installation

  • Many Linux OS images comes with this two required packages, openssh client and server already installed on it, but there are some basic images with around 700 MB which won't contain these packages.
  • To know whether you have SSH installed or not you can use the command  " which ssh " if it doesn't give any output then you will have to install it.
  •  To install SSH in CentOS use " yum install openssh* ". This command will install openssh-client and openssh-server for you.
  • To install SSH in Ubuntu use " sudo apt-get install ssh ".
  • To install CYGWIN in Windows please refer this video.

3. Uses

  • Machine with SSH client installed acts as client that can access other machine installed with SSH server.
  • Machine with SSH server installed acts as server and receives multiple request from SSH client.
  • SSH can be used to create cluster of different machines to run any job on cluster using password-less SSH login.
  •  After installing SSH client, you get Secure CoPy (SCP) facility which is  used to copy files to remote host.
To log in remote machine, enter following command

ssh -X user@IP_ADDRESS_OF_REMOTE_SYSTEM

In this command, use of -X Enables X11 forwarding. By using X11 forwarding, we can access GUI using file manager, else you will not be able to access GUI. Be aware of capital X, because small x stands for disable X11 forwarding which won't show you GUI.

4. Errors and Solutions

  • If you are unable to get access into server system, then check the user account name. That user account must be present at server side, because ssh won't give any error even if user account is not present on server side.
  •  " port 22: No route to host " this error occurs when wrong IP address which is not present is entered.
  • One common error is " port 22: Connection refused " this error occur if ssh service at remote system is stopped. You can overcome this by starting ssh service on the remote machine.
  •  Error " WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! " " IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY! "
        Cause :-  This error occurs due to change of OS at the server side or if other illegal person is using your requested server IP whose public key is known to you. Public key is stored in " known_hosts " file present in " /home/user/.ssh/ "  directory at first time when you login to server or remote machine.
        Solution :- If you want to access other machine which is not your requested  server, then you can use following command

" ssh-keygen -R IP_ADDRESS_OF_SERVER "

This command will clear or delete the entry of public key for that particular IP present in known_hosts file and create new entry and old entries are stored in " known_hosts.old "

    Read More...