msgbartop
A cronological documentation test project, nothing serious, really!
msgbarbottom

07 Dec 2007 Run X programs through ssh

A easy way to run remote X programs (from another host) on your local linux installation is to connect to it via ssh using the -Y switch.

For instance if you would like to run up2date in graphical mode on a remote machine but the server doesn’t have X installed. Then this is a great way of doing it.

On your host

ssh -Y remote_machine_name.com

When you have successfully connected to the remote host you start the up2date command.
up2date

Soon after you will get the up2date windows on your local linux machine.

Your sshd server should have enabled the X11Forwarding directive. This is enabled in your local local machines ssh config /etc/ssh/sshd_config file

X11Forwarding yes

The command you run can be anything else, for instance xterm.

Tags: , , ,

Posted by

28 Nov 2007 Deny SSH- but allow SFTP access

This is an alternative way of limiting the SSH access to only SFTP explained in my How to restrict users to SFTP only instead of SSH post.

Edit your /etc/sshd_config file and change your settings like this

Match User username
AllowTcpForwarding no
X11Forwarding no
ForceCommand /usr/libexec/sftp-server -l INFO

Replace username with the user name you would limit the SSH access for.

Tags: ,

Posted by

08 Sep 2007 Execute commands on multiple hosts using ssh

#!/bin/bash
# Linux/UNIX box with ssh key based login
SERVERS=”192.168.1.1 192.168.1.2 192.168.1.3″

# SSH User name
USR=”jadmin”

# Email
SUBJECT=”Server user login report”
EMAIL=”admin@somewhere.com”
EMAILMESSAGE=”/tmp/emailmessage.txt”

# create new file
>$EMAILMESSAGE

# connect each host and pull up user listing
for host in $SERVERS

do
echo “——————————–” >>$EMAILMESSAGE
echo “* HOST: $host ” >>$EMAILMESSAGE
echo “——————————–” >>$EMAILMESSAGE

ssh $USR@$host w >> $EMAILMESSAGE

done

# send an email using /bin/mail
/bin/mail -s “$SUBJECT” “$EMAIL” < $EMAILMESSAGE

Tags: ,

Posted by

09 Jun 2007 Synchronize current directory with remote one using rsync

This is a simple way to synchronize all the files from the current computer to a remote computer using SSH as transportation protocol.

rsync -raz --progress --delete --bwlimit=4096 /synchronize/from/this-folder/ remote-server:/to/this-folder/

This example is using PUT as transfer method because the files are put from the local computer to the remote.

Options explained

  • -r synchronize directories recursive
  • a archive, preserves file attributes, ownership, timestamps…
  • z compress data, saves bandwidth but is CPU intensive
  • –progress shows the progress of all the files that are being syncronized
  • –delete delete files remotely that no longer exist locally
  • –bwlimit=4096 specify a maximum transfer rate of 4096 kilobytes per second.

Tags: ,

Posted by

09 Jun 2007 Backup harddisk to remote machine

dd bs=1M if=/dev/hda | gzip | ssh user@remote 'dd of=hda.gz'

Tags: , , ,

Posted by