Tuesday, February 17, 2015

debug2: ssh_connect: needpriv 0 stuck - Fix.

Sometimes we face issues with SSH while connecting which is due to couple of default parameters. We can determine the delay by executing ssh command with -vv option

ssh -vv myhost
OpenSSH_5.3p1, OpenSSL 1.0.0-fips 29 Mar 2010
debug1: Reading configuration data /home/user/.ssh/config
debug2: ssh_connect: needpriv 0


1) The first, and largest cause of delays, is client and the server working to authenticate me using 'GSSAPI' (Kerberos) authentication. That seemed to be a good 15-18 seconds of the delay. To fix this problem add the following configuration file for my user that disabled GSSAPI authentication for the host.

File : /etc/ssh/ssh_config

Host *
    GSSAPIAuthentication no
    GSSAPIKeyExchange no

2) In case if we have IPv4 and IPv6 channels then above configuration wont help in the ssh delay so in that case we need to add one more line to the above configuration.

File : /etc/ssh/ssh_config

Host *
    GSSAPIAuthentication no
    GSSAPIKeyExchange no
    AddressFamily inet
In both the cases we are specifying the configuration for all the hosts we are using *, We can do it same for specific hosts.

 Instead of

Host *
Use
Host myhost-mydomain.com

File /etc/ssh/ssh_config is global configuration which is for all the users, We can do the same for individual users by specifying the same parameters in ~/.ssh/config file.
 

Friday, January 2, 2015

Get last characters of a line

Here are the two ways that we can use to get the last character of a line. 
 If you would like to get last one character then. 
 $ echo hai |tail -c 1 

 $ echo hai |tail -c 2
   i 

 
 




In linux / unix by default all most all the commands end the line with a new line and so while using the tail command we need to give -c 2 instead of -c 1. 

While using awk you can use the following syntax 

$ echo hai |awk '{print substr($0,length,1)}'
i
 
 


Friday, December 6, 2013

Shell Script to show Progress with Dots while running some commands.

If you would like to go interactive scripts and if your requirement is to show some status to user while your script is running some other set of commands with some indicators like Dots or Hash symbol and whatever you want in Shell Script then you can use the following logic.

#!/bin/bash

STATUS() {
echo -n "Copy is in Progress, Please Wait"
while true
do
echo -n "."
sleep 2
done
}

STATUS &
STAT_PID=$!
# Please all your real commands here..
dd if=/dev/zero of=/tmp/test bs=1 count=0 seek=1G >/dev/null 2>&1 
                                 ## You can redirect output to a file.

kill -9 $STAT_PID
echo -e "\nCopy Completed!"

You can run the script and you can see dots comes for every 2s and also at the same time dd command will create 1G file. Instead of dd command you can use your own commands over here and customize as per your requirement.

# ./test_progress.sh
Copy is in Progress, Please Wait......
Copy Completed!
# ls -l /tmp/test
-rw-r--r-- 1 root root 1073741824 Dec  6 23:31 /tmp/test
# ls -lh /tmp/test
-rw-r--r-- 1 root root 1.0G Dec  6 23:31 /tmp/test

Sunday, November 3, 2013

Create home directories using authconfig.



If you would like to create home directories of a user at the time of user first time login then certainly we can use authconfig command to create directory of a user as like mentioned in /etc/passwd.

authconfig --enablemkhomedir --update
If you want to disable the same feature you can use the following command.
authconfig --disablemkhomedir --update