Difference between revisions of "Linux: SSH"

From RHS Wiki
Jump to navigation Jump to search
Line 10: Line 10:
 
2 options:<br />
 
2 options:<br />
 
1:<br />
 
1:<br />
create file: /home/user/.ssh/ssh_config with the following content:
+
create file: /home/user/.ssh/ssh_config with the following content: (client side)
 
  <nowiki>
 
  <nowiki>
 
HashKnownHosts yes
 
HashKnownHosts yes
Line 16: Line 16:
 
GSSAPIDelegateCredentials no
 
GSSAPIDelegateCredentials no
 
ServerAliveInterval 120</nowiki>
 
ServerAliveInterval 120</nowiki>
 +
(server side)
 +
1
 +
$ echo "ServerAliveInterval 60" >> ~/.ssh/config
 +
  
 
2:
 
2:
 
  <nowiki>
 
  <nowiki>
 
echo 60 > /proc/sys/net/ipv4/tcp_keepalive_time</nowiki>
 
echo 60 > /proc/sys/net/ipv4/tcp_keepalive_time</nowiki>
 +
 +
Shell script to reconnect on broken pipe:
 +
<source lang="bash">
 +
#!/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
 +
</source>

Revision as of 22:56, 10 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)

1
$ echo "ServerAliveInterval 60" >> ~/.ssh/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