Friday 14 June 2013

Tips and Tricks

Make ps more readable and put on separate lines
 ps -ef | grep java | tr " " "\n"  
Show hidden files with du
 du -sk .[!.]* *| sort -n  
Show just hidden files with du
 du -sh .[a-zA-Z]*  
Trim last character in vi
 :%s/.$//g  
With sed
 sed '$s/.$//'  
Awk, print all on one line with a comma seperating
 awk '{ printf "%s,", $1 }'  
Find command with regex
 find . -name \*[Ii]nstall\*[Ll]og\*  
Remove all blank lines with awk
 awk '/./' abc.txt  
Show octal permissions when doing an ls
for file in `ls`; do echo -n `stat -c %a $file`; echo -n " "; ls -ltd $file; done  
Using awk with a field seperator
 awk 'BEGIN { FS = "," } ; { print $1 }'  
Remove HTML tags from a file
 sed "s/<[^>]\+>//g" file  

Awk print from third column to the end
 awk '{ print substr($0, index($0,$3)) }'  

Monday 3 June 2013

Passwordless ssh with Puppet

This can be achieved with the ssh_authorized_key resource type. Before doing this in puppet you need to generate a key on the host you want to ssh from. From within the user account you want the ssh access to occur from:-
 ssh-keygen  

Take a copy of the key text from /home/username/.ssh/authorized_keys. This should just be the key part not the ssh type or user and hostname. Also take a copy of the type and the user and hostname part.

Within puppet do the following:-
 ssh_authorized_key {  
  "andy@ahibbert":  
   ensure => present,  
   user  => andy,  
   type  => "ssh-rsa",  
   key  => "AAAAB....."  
 }  

In the above the details from the authorized_keys file are found:-
  • andy@ahibbert - user and hostname I'm ssh'ing from
  • type - the ssh type I am using
  • key - the public ssh key
 This file should be saved with a .pp extension and then applied as follows:-

 puppet apply auto_ssh.pp  

You should know be able to ssh without a password