|
SSH provides wounder facility to run linux command on remote machine, provided that you have SSH access to that machine…
1] I am login on machine ‘IndianGNU.org’ and trying to login to ’192.168.0.1′ ie ‘Remote’ machine.. but it immediately logout. see below….
root@IndianGNU.org:/home/arun.bagul# ssh arun.bagul@192.168.0.1
arun.bagul@192.168.0.1′s password:
Last login: Sun Jan 20 18:49:29 2008 from 192.168.0.5
Connection to 192.168.0.1 closed.
root@IndianGNU.org:/home/arun.bagul#
2] This is happening because there is ‘logout’ command added in ‘.bashrc’ file of arun.bagul‘s profile on ’192.168.0.1′
3] How to check this ‘.bashrc’ file on ’192.168.0.1′ -
root@IndianGNU.org:/home/arun.bagul# ssh arun.bagul@192.168.0.1 ‘tail /home/arun.bagul/.bashrc’
arun.bagul@192.168.0.1′s password:
if [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
######
## ‘logout’ command which will terminate your session just after login.
#You will not get any access via SSH
logout
root@IndianGNU.org:/home/arun.bagul#
4] How to remove this ‘logout’ command from remote file by ssh -
root@IndianGNU.org:/home/arun.bagul# ssh arun.bagul@192.168.0.1 ‘sed -i “s/logout/#welcome/g” /home/arun.bagul/.bashrc’
arun.bagul@192.168.0.1′s password:
root@IndianGNU.org:/home/arun.bagul#
5] Check now -
root@IndianGNU.org:/# ssh arun.bagul@192.168.0.1 ‘tail /home/arun.bagul/.bashrc’
arun.bagul@192.168.0.1′s password:
if [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
######
## ‘#welcome’ command which will terminate your session just after #login.
#You will not get any access via SSH
#welcome
root@IndianGNU.org:/home/arun.bagul#
6] Now try to login on 192.168.0.1′ with user name ‘arun.bagul’ -
root@IndianGNU.org:/home/arun.bagul# ssh arun.bagul@192.168.0.1
arun.bagul@192.168.0.1′s password:
Last login: Sun Jan 20 18:39:15 2008 from 192.168.0.5
arun.bagul@Remote:~$
7] Other uses of ssh for running remote command -
root@IndianGNU.org:/home/arun.bagul# ssh arun.bagul@192.168.0.1 ‘df -h’
arun.bagul@192.168.0.1′s password:
Filesystem Size Used Avail Use% Mounted on
/dev/hda2 79G 26G 50G 34% /
varrun 1009M 108K 1009M 1% /var/run
varlock 1009M 8.0K 1009M 1% /var/lock
udev 1009M 104K 1009M 1% /dev
devshm 1009M 0 1009M 0% /dev/shm
/dev/hda5 56G 42G 11G 81% /backup
/dev/hda1 361M 27M 315M 8% /boot
/dev/hda6 9.2G 8.6G 180M 98% /var
root@IndianGNU.org:/home/arun.bagul#
** List mounted partion -
root@IndianGNU.org:/home/arun.bagul# ssh root@192.168.0.8 ‘mount’
root@192.168.0.8′s password:
/dev/hda3 on / type ext3 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
/dev/hda2 on /boot type ext3 (rw)
tmpfs on /dev/shm type tmpfs (rw)
/dev/hda7 on /usr type ext3 (rw)
/dev/hda6 on /var type ext3 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
/usr/tmpDSK on /tmp type ext3 (rw,noexec,nosuid,loop=/dev/loop0)
/tmp on /var/tmp type none (rw,noexec,nosuid,bind)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
root@IndianGNU.org:/home/arun.bagul#
Regards,
Arun Bagul