posts under ssh tag

Close a remote SSH session

To close all SSH sessions of a given user :

skill -KILL -u username

You can list connected users with the who command.

Mount a distant directory over SSH

You need to install the sshfs package :

sudo apt-get install sshfs

Then, just create a local directory and mount your distant one inside :

mkdir ~/my_distant_directory
sshfs [user@]host:[dir] ~/my_distant_directory

To umount it :

fusermount -u ~/my_distant_directory

Secure your SSH transactions with keys

To automate rsync backups between 2 Linux machines, you have to use SSH keys. These keys allow you to connect through SSH without typing any password.

First, you need to generate public key on the client (only for the current user). Do not answer to the following questions :

ssh-keygen -t dsa -b 1024

Now, you have 2 generated files for the current user : ~/.ssh/id_dsa for the private key and ~/.ssh/id_dsa.pub for the public one. Then, you must copy the public key to the server authorized keys's list and that's all !

ssh-copy-id -i ~/.ssh/id_dsa.pub distant_user@server

Deactivate SSH timeout

To deactivate sshd timeout, just add these lines at the end of your /etc/ssh/sshd_config :

KeepAlive yes
ClientAliveInterval 60

And don't forget to restart the daemon :

sudo /etc/init.d/ssh restart