#!/bin/bash
# Script to create a CSV formatted text with a file of a few lines having one entry per line.
# This will merge the files line by line
for i in `cat test`; do echo $i > out/$i.out; done;
paste -d, out/*
Friday, November 12, 2010
Sunday, October 17, 2010
Problem with passwordless SSH as ROOT equivalent user
Password less SSH using RSA/DSA public key helps a lot in automated file copying, scripts, cron, etc. but there found a trouble when a root equivalent user will try this mechanism.
It wont work if you just copy/append the public key to remote server's ~/.ssh/authorized_keys. The wrong thing here is when you generate public key it will make one with username root instead of the real user's name since the UID is 0. The hack to be done to fix this is just change the username at the end of the public key in authorized_keys at remote server.
. Change the username entry of Public key at remote location in authorized_keys from root to USER. If you have a single entry in authorized_keys you can run the below command. Otherwise open it in an editor and replace the ROOT with USERNAME for the specific key.
# sed -i 's/root/USER/g' /home/USER/.ssh/authorized_keys
Other general things to be taken care in SSH key mechanism are
· Set user and group of /home/USER to USER
# chown USER.USER –R /home/USER
· Changed the permission of /home/USER/.ssh to 700
# chown 700 /home/USER/.ssh
· Changed the permission of all files under /home/USER/.ssh to 600
# chmod go-rwx /home/USER/.ssh/*
· Use ssh –i /home/USER/.ssh/id_rsa option for password less authentication
· Restart SSHD.
It wont work if you just copy/append the public key to remote server's ~/.ssh/authorized_keys. The wrong thing here is when you generate public key it will make one with username root instead of the real user's name since the UID is 0. The hack to be done to fix this is just change the username at the end of the public key in authorized_keys at remote server.
. Change the username entry of Public key at remote location in authorized_keys from root to USER. If you have a single entry in authorized_keys you can run the below command. Otherwise open it in an editor and replace the ROOT with USERNAME for the specific key.
# sed -i 's/root/USER/g' /home/USER/.ssh/authorized_keys
Other general things to be taken care in SSH key mechanism are
· Set user and group of /home/USER to USER
# chown USER.USER –R /home/USER
· Changed the permission of /home/USER/.ssh to 700
# chown 700 /home/USER/.ssh
· Changed the permission of all files under /home/USER/.ssh to 600
# chmod go-rwx /home/USER/.ssh/*
· Use ssh –i /home/USER/.ssh/id_rsa option for password less authentication
· Restart SSHD.
Tuesday, February 23, 2010
Backup of CRON list and jobs
#!/bin/bash
# Author: haritux.in
# To be ran as root or SUDO
echo Enter the destination directory for backup
read DEST
OUT=`hostname`_crons.`date +%d%m%Y-%H%M%S`
mkdir -p $DEST/$OUT 2&> /dev/null
cd $DEST/$OUT
for i in `ls /var/spool/cron/crontabs/` ### Debian, Ubuntu
#for i in `ls /var/spool/cron/` ### Red Hat, CentOS, Fedora
do
grep $i /etc/passwd
if [ $? = 0 ]; then
{
crontab -u $i -l >> $i.cronlist.txt
}
fi
done
cd ..
tar -czf $OUT.tar.gz2 $OUT
rm -rf $OUT
Tuesday, February 9, 2010
SSH Launcher
#!/bin/bash
echo Select the hostname to SSH
HOSTS=/home/psychotux/scripts/conf/hosts.txt
cat $HOSTS | cut -f3 -d'|'
read host
echo Enter your username number
IP=`grep $host $HOSTS | cut -f2 -d'|'`
ssh "$user"@$IP
Note: /home/psychotux/scripts/conf/hosts.txt will be a file with values HOSTNAME and IP ADDRESS separated by "|"
echo Select the hostname to SSH
HOSTS=/home/psychotux/scripts/conf/hosts.txt
cat $HOSTS | cut -f3 -d'|'
read host
echo Enter your username number
IP=`grep $host $HOSTS | cut -f2 -d'|'`
ssh "$user"@$IP
Note: /home/psychotux/scripts/conf/hosts.txt will be a file with values HOSTNAME and IP ADDRESS separated by "|"
Thursday, December 17, 2009
SED-Replace multiple lines with a single line
A useful option of sed command to replace multiple lines with a single line upon matching a given string.
$ cat -n file.txt
Hello world
Hello nobody
nobody
Somebody
anybody
If you want to replace the lines 2 and 3 with another line "Hello everybody" the below command will help.
$ sed '/nobody$/{N;s/Hello nobody\nnobody/Hello everybody/}' file.txt
$ cat -n file.txt
1 hello world
2 Hello everybody
3 Somebody
4 anybody
$ cat -n file.txt
Hello world
Hello nobody
nobody
Somebody
anybody
If you want to replace the lines 2 and 3 with another line "Hello everybody" the below command will help.
$ sed '/nobody$/{N;s/Hello nobody\nnobody/Hello everybody/}' file.txt
$ cat -n file.txt
1 hello world
2 Hello everybody
3 Somebody
4 anybody
SMTP authentication through TELNET
It's common that we use TELNET to port 25 of Mail server to check the connectivity and to ensure the Mail flow.
It's also possible to perform SMTP authentication in TELNET session
$ telnet yourmailserver 25
type “HELO”, hit Enter.
AUTH LOGIN
Now you have to enter your email ID and then your password encoded in BASE64.
For converting your email and password to Base64 use the conversion tools at WebPan or Ostermiller
Reference
WebPan.com
KongTechnology
It's also possible to perform SMTP authentication in TELNET session
$ telnet yourmailserver 25
type “HELO”, hit Enter.
AUTH LOGIN
Now you have to enter your email ID and then your password encoded in BASE64.
For converting your email and password to Base64 use the conversion tools at WebPan or Ostermiller
Reference
WebPan.com
KongTechnology
echo colourfully
# for i in `cat num.txt`; do echo -en '\E[3'$i'm'"\033[1mPsycho Tux\033[0m " ; done;
# for i in `cat num.txt`; do echo -en '\E[47;3'$i'm'"\033[1mPsycho Tux\033[0m " ; done;
# cat num.txt
1
2
3
4
5
6
7
8
9
0
# for i in `cat num.txt`; do echo -en '\E[47;3'$i'm'"\033[1mPsycho Tux\033[0m " ; done;
# cat num.txt
1
2
3
4
5
6
7
8
9
0
Subscribe to:
Posts (Atom)
AT&T USA | Internet not working | Fix by custom APN
If the AT&T Mobile internet is not working on your cellphone, it can be fixed easily by adding an APN configuration. You can read this a...
-
Hi there, You all know how to check TCP port connectivity from a Linux or UNIX machine to a remote machine using telnet as per th exampl...
-
Before you start Ensure that you have installed wvdial, usbmodeswitch and usbmodeswitch_data # dpkg -l | grep wvdial # dpkg -l | grep ...
-
Bored of Black screened Task bar filling putty? Issues with porting Saved sessions from machine to machine? Do you like tabbed SSH sessions?...