Thursday, 10 March 2016

How to run a command on Remote server without login to server shell prompt ?


How to run a command on Remote server without login to server shell prompt ?

 

By using SSH command, You can run a command on remote server without login to server shell.

SSH Command Format:

# ssh remoteuser@remotehost remotecommand

Suppose I want to run ls command on remote server pk.testmail.com

parveen@Earth:~$ ssh root@pk.testmail.com ls

 The authenticity of host ' pk.testmail.com (x.x.x.x)' can't be established.

 RSA key fingerprint is 7d:74:91:ed:30:1e:86:0b:69:c9:77:0b:72:0e:ad:4e.

 Are you sure you want to continue connecting (yes/no)? yes

 Warning: Permanently added 'pk.testmail.com' (RSA) to the list of known hosts.

 root@pk.testmail.com's password:

 

anaconda-ks.cfg

downloads

install.log

install.log.syslog

Note : – When we run any command on remote server, by default ssh will not allocate a pseudoterminal. For using pseudoterminal we have to use -t option with ssh command as explained below.

parveen@Earth:~$ ssh -t root@ pk.testmail.com ls

 root@pk.testmail.com's password:

 anaconda-ks.cfg  downloads  install.log  install.log.syslog

 Connection to pk.testmail.com closed.

Now you can see, Command out put will be same as we run same command after login to remote server.

To run multiple commands on remote server, use semi-colon between commands as shown below:

parveen@Earth:~$ ssh -t root@ pk.testmail.com "ls ; df -h ; date ; cal"

 root@pk.testmail.com's password:

 anaconda-ks.cfg  downloads  install.log  install.log.syslog  server_invalid_mails_cleanup.sh

 Filesystem      Size  Used Avail Use% Mounted on

 /dev/vda         20G  6.9G   12G  37% /

 tmpfs           246M     0  246M   0% /dev/shm

 Mon Nov 10 00:52:12 EST 2014

 November 2014

 Su Mo Tu We Th Fr Sa

 1

 2  3  4  5  6  7  8

 9 10 11 12 13 14 15

 16 17 18 19 20 21 22

 23 24 25 26 27 28 29

 30

 Connection to pk.testmail.com closed.

We can also use echo command to run a remotecommand on remoteserver.

parveen@Earth:~$ echo "ls" | ssh root@pk.testmail.com

 Pseudo-terminal will not be allocated because stdin is not a terminal.

 root@pk.testmail.com's password:

 anaconda-ks.cfg

 downloads

 install.log

 install.log.syslog

Note:- We can’t use -t option with ssh command to run remotecommand using echo command because Pseudo-terminal will not be allocated because stdin is not a terminal.

Use ssh command with tar command to move a directory of files between two machines as an alternative to scp command. Example is explained below:

parveen@Earth:~$ tar -cvf - images/test1 | ssh root@ pk.testmail.com  '(cd /tmp/; tar -xf -)'

 images/test1/

 images/test1/7

 images/test1/6

 images/test1/5

 images/test1/4

 images/test1/9

 images/test1/8

 images/test1/3

 images/test1/2

 images/test1/1

 root@pk.testmail.com's password:

 

Now files are uploaded on Remote server. Check files on remote server as shown below.

 

[root@pk tmp]# ls -l images/

 total 4

 drwxrwxr-x 2 1000 1000 4096 Nov 10 01:02 test1

 [root@pk tmp]# ls -l images/test1/

 total 0

 -rw-rw-r-- 1 1000 1000 0 Nov 10 01:02 1

 -rw-rw-r-- 1 1000 1000 0 Nov 10 01:02 2

 -rw-rw-r-- 1 1000 1000 0 Nov 10 01:02 3

 -rw-rw-r-- 1 1000 1000 0 Nov 10 01:02 4

 -rw-rw-r-- 1 1000 1000 0 Nov 10 01:02 5

 -rw-rw-r-- 1 1000 1000 0 Nov 10 01:02 6

 -rw-rw-r-- 1 1000 1000 0 Nov 10 01:02 7

 -rw-rw-r-- 1 1000 1000 0 Nov 10 01:02 8

 -rw-rw-r-- 1 1000 1000 0 Nov 10 01:02 9

 

 

Sunday, 14 February 2016

SCP (Secure Copy) Command Tutorial with Practical Examples


SCP (Secure Copy) Command Tutorial with Practical Examples

 

Overview :

This tutorial will help the system administrators to know how to securely copy files to remote linux servers from local linux machine & vice versa in UNIX like operating system.  SCP stands for Secure Copy ,it copies files between hosts over a  network.  It uses ssh for data transfer &  uses the same authentication and provides the same security as ssh. Unlike rcp, scp will ask for passwords or passphrases if they are needed for authentication.

Below is the Syntax of copying File from Local Machine To Remote Machine

# scp examplefile username@Remote-Server:/home/

Above command will copy examplefile to remote under /home folder , it will ask the password of username mentioned in the command.

Syntax for Copying files from remote server to your local Machine

# scp username@Remote-Server:/home/examplefile /home

Above command will copy examplefile from remote Server’s /home folder to local machine’s home folder.

Some of the commonly used options in scp command.

  •  -r : Recursively copies the contents of source files or directories.
  • -p : Preserves the access time, modification time, permissions of the source files in the destination.
  • -q : disables the progress bar as well as warning & diagnostic messages from ssh.
  • -v : verbose mode. Displays debugging messages.
  • -P : copy files using the specified port number.
  • -l limit :  Limits the used bandwidth, specified in Kbit/s.
    Example:1 Copy the file “itstuff.txt” from a remote host to the local machine
    [root@linux ~]# scp root@mail.nextstep4it.com:/opt/itstuff.txt  /home
    root@mail.nextstep4it.com's password:
    itstuff.txt                                          100% 1024KB   5.0KB/s   03:23
     
    Example:2 Copy the file “itstuff.txt” from the local machine to a remote host
    [root@linux ~]# scp  /home/itstuff.txt   root@mail.nextstep4it.com:/opt/
    root@mail.nextstep4it.com's password:
    itstuff.txt                                          100% 1024KB   1.0MB/s   00:00
     
    Example:3 Copy the directory “data” from the local host to a remote host’s directory /opt using ‘-r’ option.
    [root@linux opt]# scp -r data  root@mail.nextstep4it.com:/opt
     root@mail.nextstep4it.com's password:
     file5                                                 100%    0     0.0KB/s   00:00
     file3                                                 100%    0     0.0KB/s   00:00
     file1                                                 100%    0     0.0KB/s   00:00
     file2                                                 100%    0     0.0KB/s   00:00
     file4                                                 100%    0     0.0KB/s   00:00
     
     Example:4 Copy multiple files from the remote host to your current directory on the local machine
    [root@linux ~]# scp  root@mail.nextstep4it.com:/opt/data/\{file1,file2,file3} .
     root@mail.nextstep4it.com's password:
     file1                                                  100%    0     0.0KB/s   00:00
     file2                                                  100%    0     0.0KB/s   00:00
     file3                                                  100%    0     0.0KB/s   00:00
     
     Example:5 Copy the file “itstuff.txt” from the local machine to a remote host using port 2751.
    [root@linux ~]# scp -P 2751 /home/itstuff.txt root@mail.nextstep4it:/opt
     
    Example:6 Copy files from local machine to remote host using blowfish options.
    By default scp uses the Triple-DES cipher to encrypt the data being copied. Using the Blowfish cipher we can increase speed. This can be done by using option -c blowfish in the command line.
    [root@linux ~]# scp -c blowfish /home/itstuff.txt root@mail.nextstep4it.com:/opt/
    root@mail.nextstep4it.com's password:
    itstuff.txt                                           100% 1024KB   1.0MB/s   00:00
     
    Example:7 Limit the bandwidth used by the scp command using the ‘-l’ option.
    We can limit the bandwidth used by the scp command using ‘-l’ option as shown in the below syntax
    # scp -l bandwidth_limit filename username@remote-host:/folder-name
    where bandwidth_limit is numeric to be specified in kilobits per second.
     
     

Tuesday, 5 January 2016

Mail Server Components – MTA , MDA & MUA


Mail Server Components – MTA , MDA & MUA

 

Overview:

In general, all email servers consists of three main components: MTA , MDA & MUA. Each components plays a specific role in the process of moving and managing email messages. While most users are only aware of the specific email program they use to receive and send messages, each one is important for ensuring that email arrives at the correct destination.

Mail Transport Agent(MTA)

A Mail Transport Agent (MTA) transports email messages between hosts using SMTP. A message may involve several MTAs as it moves to its intended destination.

While the delivery of messages between machines may seem rather straightforward, the entire process of deciding if a particular MTA can or should accept a message for delivery is quite complicated. In addition, due to problems from spam, use of a particular MTA is usually restricted by the MTA’s configuration or the access configuration for the network on which the MTA resides.

Many modern email client programs can act as an MTA when sending email. However, this action should not be confused with the role of a true MTA. The sole reason email client programs are capable of sending email like an MTA is because the host running the application does not have its own MTA. This is particularly true for email client programs on non-UNIX-based operating systems. However, these client programs only send outbound messages to an MTA they are authorized to use and do not directly deliver the message to the intended recipient’s email server.

Since Red Hat Enterprise Linux offers two MTAs, Postfix and Sendmail, email client programs are often not required to act as an MTA. Red Hat Enterprise Linux also includes a special purpose MTA called Fetchmail.

Mail Delivery Agent (MDA)

A Mail Delivery Agent (MDA) is invoked by the MTA to file incoming email in the proper user’s mailbox. In many cases, the MDA is actually a Local Delivery Agent (LDA), such as mail or Procmail.

Any program that actually handles a message for delivery to the point where it can be read by an email client application can be considered an MDA. For this reason, some MTAs (such as Sendmail and Postfix) can fill the role of an MDA when they append new email messages to a local user’s mail spool file. In general, MDAs do not transport messages between systems nor do they provide a user interface; MDAs distribute and sort messages on the local machine for an email client application to access.

Mail User Agent(MUA)

A Mail User Agent (MUA) is synonymous with an email client application. An MUA is a program that, at a minimum, allows a user to read and compose email messages. Many MUAs are capable of retrieving messages via the POP or IMAPprotocols, setting up mailboxes to store messages, and sending outbound messages to an MTA.

MUAs may be graphical, such as Evolution,Thunderbird & Outlook, or have simple text-based interfaces, such as Mutt

 

Thursday, 10 December 2015

Linux Boot Process


Linux Boot Process

 

In this article we are going to study “Linux Boot Process”. During booting time of Linux operating system, boot process have to go through six basic stages.

Boot Stage 1:

BIOS Checks: When a Linux server or desktop or laptop booted, The processor goes for Basic Input/Output System or BIOS program and runs it.The BIOS controls does not controll only the first step of the boot process, but BIOS also provides the lowest level interface to peripheral devices. It means during the BIOS initialization, all hardware peripheral devices checked out by BIOS. If BIOS found any hardware is faulty, you will get message on your screen.For this reason BIOS Process is written into read-only mode.The BIOS then loads into memory whatever program is residing in the first sector of this device, called the Master Boot Record or MBR. The MBR is only 512 bytes in size and contains machine code instructions for booting the machine, called a boot loader, along with the partition table. Once the BIOS finds and loads the boot loader program into memory,it yields control of the boot process to it.

Note: The default boot loader for Linux platform is GRUB.

Boot Stage 2:

First stage boot loader: The first stage of Boot Loader is a small machine code binary on MBR. The first stage boot loader loads itself into memory.first stage boot loader job is to find out the second stage boot loader and load the first part of it into memory.

Boot Stage 3:

Second stage boot loader: The second stage boot loader loads the kernel into memory, which in turn loads any necessary modules and mounts the root partition read-only. Once the second stage boot loader is in memory, it presents the user with a graphical screen showing the different operating systems or kernels that has been configured to boot. You can use Arrow keys to select your operating system for boot.

Stage 3.5: the Second Stage Bootloader loads the Linux Kernel and hands control to it. The Kernel takes control of the hardware. This includes taking control of the memory management hardware, timers, interrupts, etc. The processor is no longer in x86 16-bit mode like it was when the BIOS started. The kernel will start using other processors and/or additional cores within processors. Linux may have some modules pre-compiled into the kernal, and may also load some modules from disk as needed, such as device driver modules that apply to the actual hardware present on this system. Once the kernel is fully running, it starts a single user space process, which is the ancestor of all processes: /sbin/init. Up until this point, all Linux systems work very similarly. Once /sbin/init begins, this is where the major differences between distributions become highly visible.

Boot Stage 4:

INIT Program: The Linux operating system kernel transfers the control of the boot process to the /sbin/init program.The /sbin/init program  coordinates the rest of the boot process and configures the environment for the user.

Boot Stage 5:

User Environment Setup: The init program loads all services and user-space tools, and mounts all partitions listed in /etc/fstab. When the init command starts, it becomes the parent or grandparent of all of the processes that start up automatically on the system. First, it runs the /etc/rc.d/rc.sysinit script, which sets the environment path, starts swap, checks the file systems, and executes all other steps required for system initialization.The init command then runs the /etc/inittab script, which describes how the system should be set up in each SysV init runlevel.The init program starts all of the background processes by looking in the appropriate rc directory for the runlevel specified as the default in /etc/inittab. The rc directories are numbered to correspond to the runlevel they represent.

Note: By Default, run level 5 is defined in /ete/inittab file.

Boot Stage 6:

Login Screen: The user will get a login screen for the freshly booted Linux system.

 

Tuesday, 12 May 2015

Linux Interview Questions For Experienced

Why should you periodically update the kernel and package versions?
To enhance the security of system you should ensure that you are using the latest versions kernel and software packages that contain the most recent security updates.
During a recent strikes at office, several archive tapes of the system were damaged and ruined. What can you do to prevent the physical damage in future?
You should store them at offsite.
Why should you avoid the Telnet to administer a Linux system remotely?
Telnet use most insecure method for communication. It send data across the network in plain text format. Someone easily find out the password using the network tool.
A file is unable to be restored from tape due to several device and media errors. What is most likely the cause?
Media errors usually indicate that the tape media is damaged, or that the tape drive heads need cleaning.
Your FTP Server recently hacked. Due to the amount of damage, the entire server needs to be restored. How should you restore the original kernel system files?
You cannot restore the entire operating system from tap back up device. So you should reinstall the core operating system, and then restore system configuration files and user data from tape backup device.
Your company hire a contract employee for two months. What should the Linux administrator do to enhance security on the employee's account?
While creating new user account for this user, administrator should set the expiration date for his account, so that if the employee leaves or does not have their contract renewed, the account will be automatically disabled.
Which backup strategy only backs up files that have changed since the last full backup?
Differential backup will backup files that have changed since the last full backup.
Name a service which should you disable on a Linux Server which is acting as both a Web and FTP Server.
The finger service should be disabled because a remote user can get important information about the system by using that command.
Why it is recommended to store backup tapes to an offsite storage facility?
Because this will prevent the backup taps from being destroyed during a natural disaster at the server site. It also prevents the tapes from being stolen.
A newbie enabled the root session for FTP server. is it ok?
No, he has put the security of entire server on risk. You should disable to root session as soon as possible.
A user complains you that he is unable to set '123' as his password. Why would not the system allow this password?
There would be a minimum length rule for password, which is blocking user to use this password. Default minimum length rule for password is six characters. It means a user cannot have password less than six characters.
Your company is running Web Server. One dedicate account holder customer complains that his visitors are able to scan the directory tree. Which directive would you configure to stop web server from listing the directory?
You should remove / comment the "Options Indexes" directive from the main configuration file ' httpd.conf' of the web server. This is a security measure so that remote users can’t scan the directory tree of the server looking for security holes. Server won’t show directory listings if requested by a user.
What type of backup strategy can you use to fully back up a system every night?
You can use full backup strategy that will always perform a full backup of all files. This takes much more time and space than other methods, but is it the most complete method and allows for easy file restoration.
How can you enhance the security of password file?
Linux keep user account information in a text file called /etc/passwd. This file also store one way encrypted password. This file is accessed by several tools to get user information, so file need to world readable. This is a security risk. To minimize the security risk you can use shadow password format. This method save account information in regular file /etc/passwd. However, the password is stored as a single "x" character (not actually stored in this file). A second file, called "/etc/shadow", contains encrypted password as well as other information such as account or password expiration values, etc. The /etc/shadow file is readable only by the root account and is therefore less of a security risk
What command should be used to make a tar archive to a disk file system located in /mnt/backup?
The correct command is tar -cvf /mnt/backup. The /mnt/backup directory should be on another machine to be fully effective as a backup strategy.
You have just finished the installation of sever. This server is going to be use as file server. Default installation have send mail service running, while this server will never send any e-mails. How should you deal with send mail service?
You should disable the send mail service if server is not being used for mail purpose. Leaving them running can increase the chance of a security vulnerability being exploited, and unauthorized use of sendmail relay.
What command can you use to back up an entire file system most efficiently?
The easiest command to use to back up an entire file system is the dump command. Files can be restored from a dump operation by using the restore command.
Which necessary steps should you take to enhance the security of server just after the initial installation?
  • Kernel and packages should be upgraded to the latest versions.
  • Unnecessary services and daemons should be disable.
  • Enable and configure firewall
  • Set a complex password policy.
While auditing user accounts, an administrator notices that one of the users has a blank password. What should he do to the account?
To prevent further use of the account, which is an immediate security risk, disable it and set a temporary password for the user for the next time they login.
Which backup strategy backs up all files that have changed since the last backup?
An incremental backup will only back up files that have changed since the last backup.
Your company has terminated a server administrator. What is first thing as an administrator should you do to enhance the security?
Because the server administrator knows the root password for the server, it should be changed immediately to prevent them from tampering with the system.
You are setting up an FTP server. Only company employees are allowed to use the FTP services. What should you configure on the FTP server to enhance security?
You should disable the anonymous FTP account, so that only users with a username and password can access the system.
What is the location of system configuration files that should be backed up on a regular basis?
The /etc directory contains most of the Linux system configuration files.
Which permission allows a user to run an executable with the permissions of the owner of that file?
The Set-User-ID is a special permission that allows a user to run an executable with the permissions of the owner of that file.
What command can you use to make a tape archive file of a /home directory, and send it to the /dev/tape device?
The correct command is tar -cvf /dev/tape /home.
The -xvf option is used to extract files from an archive.
Employees at your company are lazy in changing the password. As a system administrator what can you do to minimize the security risk?
You can setup a password policy which enforce user to change his password after a specific time periods.
Which program should you use to connect a system remotely?
You should always use SSH to connect a system remotely. SSH is a secure method that encrypts the entire session.
To save disk space, an administrator wants to backup files, and then remove them from the server permanently. What kind of backup operation is this?
An archive operation will take the files, back them up to a device, and then remove the files from the original server.
What does firewall do?
Firewall is a device or service which can be used to protect the network or system from other outside networks.

Wednesday, 22 April 2015

linux interview questions FOR RHCE

Which version of RHEL officially supports LUKS encryption?

From version 6 or higher LUKS encryption is officially supported by RHEL.

What is the default virtualization technology for RHEL6 ?

Default virtualization technology is KVM.

Can you configure KVM Virtual machine on 32 bit system ?

No, KVM virtualization requires at least 64 bit system.

What is default mode of SELinux during the installation of RHEL ?

  • In RHEL5 you have to choose the mode which you want.
  • From RHEL6 default mode is Enforcing during the installation.
However you can change the mode of SELinux after installation, only difference between RHEL5 and RHEL6 is that in RHEL5 asks you to choose the mode while RHEL6 does not let you to choose the mode during the installation.

Which remote management service is allowed through the default firewall and by default installed in RHEL?

By default SSH is always installed in RHEL. SSH uses port 22 which is allowed through the default firewall rules.

Which standard directory is used by vsFTP server for file sharing ?

Default Standard directory for ftp is /var/ftp/pub.

Which standard directory is used by Apache web server for HTML files ?

standard directory for HTML files is /var/www/html

What is the default partition layout during the installation ?

Default partition Layout is the LVM.

Which necessary partition cannot be a part of logical volume group ?

boot partition cannot be a part of logical volume group. You must have create it as a regular partition.

Which partitions are recommended for custom layout of partition ?

  • /
  • /boot
  • /home
  • swap

What step during the installation could you take to prevent a program from creating temporary files that fill up the entire space ?

You can create a separate /tmp partition prevents a program from creating temporary files that fill up the entire filesystem.

What is the kickstart ?

kickstart is a installation method used in RHEL. A kickstart installation is started from a kickstart file, which contains the answers to all the questions in the installation program.

Name any of two third party distribution based on RHEL6 source code.

CentOS and Scientific Linux

Which Log file contains all installation message?

install.log.syslog file contains all messages that were generated during the installation.

Wednesday, 8 April 2015

linux interview questions 1

What is Kerberos used for?

Kerberos is used for secure network logon.
Which partition store system configuration files in Linux system?
/etc partition stores system configuration files in Linux.
What is the purpose of the MD5 option on passwords?
MD5 is an encryption method that encrypts the password before saving.
Name any four general password rules for user account.
  • Include at least eight total characters
  • Use the string in an unrepeated way
  • Avoid use words that can be found in the dictionary
  • Avoid use dates of significance, such as a birthday or anniversary
A better method of password security is to create difficult-to-break passwords that are easy for the users to remember.
What is the alternative method to a GUI installation in Linux ?
Linux provides text base installation as the alternative method of GUI installation.
What is the purpose of the swapon command ?
swapon command is used to activate a already created swap partition. It cannot be used to create a new swap partition.

What is gzip?

gzip is a compression utility created by the GNU project.

What is tar?

tar is an archive utility that is used to create tape backups.
Which is the standard command used to uncompress gzip files?
The standard command used to uncompress gzip files is gunzip.
What is the RPM switch for only installing packages?
The command line switch for installing an RPM is -i.
What is the command used to install an RPM package named demofilename2.2-2.i386.rpm?
The most common command used to install an RPM package is rpm -ivh. Following command will install the given package
#rpm -ivh demofilename2.2-2.i386.rpm
What is the command used to remove an RPM package named demofilename2.2-2.i386.rpm?
The most common command used to remove an RPM package is rpm -evh. Following command will remove the given package
#rpm -evh demofilename2.2-2.i386.rpm
What is the command used to update an RPM package named demofilename2.2-2.i386.rpm?
The most common command used to update an RPM package is rpm -Uvh. Following command will update the given package and remove the old.
#rpm -Uvh demofilename2.2-2.i386.rpm
Which command is used to see which RPM version of gzip was installed on the system?
#rpm -q gzip
Where are the automatically mounted file systems listed?
The automatically mounted file systems are listed in the file /etc/fstab.
While installing the new RPM what common steps should take ?
You should follow these common steps
  • Use RPM tools should be used to query or verify the installed packages to
  • confirm the installation of any previous packages.
  • Check the signature of new package
  • RPM should be installed or upgraded by first using the test mode to verify that it works, and then it should be installed
  • At the end query the RPM and verify the installation of RPM
Which organization controls the official releases and updates of the X Window System?
The X Consortium at www.x.org controls the official release and updating of the X Window System
PPP is most often used to create?
PPP is most often used to create serial point-to-point connections.
When attempting to connect to www.example.com you got unknown host message. Which service is most likely not functioning properly?
DNS
Samba is used to provide support for which protocol?
Samba is used to support the Microsoft SMB/CIFS systems.
What command is used to load a module into the kernel?
The insmod command is used to load a module into the kernel
Name one of the most secure method of remote access.
SSH is the most secure method of remote access
With respect to a Linux system’s RAM, how large should the swap file be?
Generally the size of the swap file should be twice the size of installed RAM.
How would you create a backup of the fstab file to the /backup folder?
Use cp command to create the backup.
#cp /etc/fstab /backup
What command is used to exit the edit mode of VI editor?
The [esc] key is used to exit from the edit mode of VI editor.
What key combination will exit from VI editor and not save the changes made?
Esc + q +! Key combination will exit VI without saving the changes.
What command would you use to create a file system on a new hard drive?
The mkfs command is used to create file systems.

What fstab file do?

The fstab file is used to automatically mount file systems.

What inittab file do?

The /etc/inittab file is used to perform the default state and terminal connections for a Linux system.
What command can you use to verify the current active shell?
The env command will display the current active shell.
Where is the file . bashrc located?
The . bashrc file is usually located in the /home/username directory.
What function does the .bash_profile file perform?
The function of the .bash_profile file is to provide login initialization commands.
What function does the .bash_logout file perform?
The function of the .bash_logout is to provide logout functions
What function does the .bashrc file perform?
The function of the .bashrc file is to provide shell configuration commands.