Difference between revisions of "Linux: SSH"

From RHS Wiki
Jump to navigation Jump to search
Line 16: Line 16:
 
GSSAPIDelegateCredentials no
 
GSSAPIDelegateCredentials no
 
ServerAliveInterval 120</nowiki>
 
ServerAliveInterval 120</nowiki>
(server side)
+
(server side) This one worked!!
 
  echo "ClientAliveInterval 60" | sudo tee -a /etc/ssh/sshd_config
 
  echo "ClientAliveInterval 60" | sudo tee -a /etc/ssh/sshd_config
  

Revision as of 22:27, 12 April 2015

Config file

sudo nano /etc/ssh/sshd_config

Welcome message

Two files must be edited:
/etc/motd (message of the day)
/etc/ssh/sshd_config: Change the setting PrintLastLog to "no", this will disable the "Last login" message.

Convert rsa to ppk

puttygen keyname -o keyname.ppk

Avoid broken pipe

2 options:
1:
create file: /home/user/.ssh/ssh_config with the following content: (client side)

HashKnownHosts yes
GSSAPIAuthentication yes
GSSAPIDelegateCredentials no
ServerAliveInterval 120

(server side) This one worked!!

echo "ClientAliveInterval 60" | sudo tee -a /etc/ssh/sshd_config


2:

echo 60 > /proc/sys/net/ipv4/tcp_keepalive_time

Shell script to reconnect on broken pipe:

#!/bin/sh

#This is an SSH-D proxy with auto-reconnect on disconnect

#Created by Liang Sun on 28, Sep, 2011
#Email: i@liangsun.org

i=0
while test 1==1
do
    remote_ip=YOUR_REMOTE_IP
    remote_user=YOUR_REMOTE_USER
    local_port=YOUR_LOCAL_PORT

    exist=`ps aux | grep $remote_user@$remote_ip | grep $local_port`
    #echo $exist
    if test -n "$exist"
    then
        if test $i -eq 0
        then
            echo "I'm alive since $(date)"
        fi
        i=1
    else
        i=0
        echo "I died... God is bringing me back..."
        ssh $remote_user@$remote_ip -f -N -D 0.0.0.0:$local_port
    fi
    sleep 1
done