Pejman Moghadam / General

SSh Tunnel

Public domain


RemoteInvalidIP:RemotePort forward to LocalIP:LocalPort

ssh username@RemoteValidIP -L LocalIP:LocalPort:RemoteInvalidIP:RemotePort -N

LocalInvalidIP:LocalPort forward to Remote127.0.01:RemotePort

ssh username@RemoteValidIP -R RemotePort:LocalInvalidIP:LocalPort -N

Remote Desktop (rdp)

ssh 10.11.12.1 -L 172.16.20.2:3389:10.11.12.20:3389 -N

PCAnyWhere

ssh 10.11.12.1 -L 172.16.20.2:5631:10.11.12.20:5631 -D 172.16.20.2:5632 -N

SSH CallBack

ssh user@10.11.12.1 -R 2222:172.16.20.2:22 -N

Automatic ssh tunnel (freebsd)

Server:

# adduser
Username: pejman
Full name: Pejman Moghadam
Uid (Leave empty for default):
Login group [pejman]:
Login group is pejman. Invite pejman into other groups? []:
Login class [default]:
Shell (sh csh tcsh nologin) [sh]:
Home directory [/home/pejman]:
Use password-based authentication? [yes]:
Use an empty password? (yes/no) [no]:
Use a random password? (yes/no) [no]:
Enter password: pass123456
Enter password again: pass123456
Lock out the account after creation? [no]:
Username   : pejman
Password   : *****
Full Name  : Pejman Moghadam
Uid        : 1001
Class      :
Groups     : pejman
Home       : /home/pejman
Shell      : /bin/sh
Locked     : no
OK? (yes/no): yes
adduser: INFO: Successfully added (pejman) to the user database.
Add another user? (yes/no): no
Goodbye!

# su pejman
$ cd
$ pwd
/home/pejman
$ mkdir .ssh
$ exit

Client:

# vi /etc/hosts
    10.20.30.100          sshserver

# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
ef:fb:69:f3:82:e4:bc:32:f3:11:88:40:67:2c:64:f6 root@reza.12345

 # ssh-copy-id -i /root/.ssh/id_rsa.pub pejman@sshserver
or :
 # scp /root/.ssh/id_rsa.pub pejman@sshserver:/home/pejman/.ssh/new-authorized_keys2
test :
 # ssh -L 5050:localhost:5050 pejman@sshserver

# cd /usr/ports/lang/php5
# make install clean && rehash

# vi /usr/local/sbin/ssh-tunnel.php
    #!/usr/local/bin/php
    < ? php
    $port   = 5000;
    $ip     = "localhost";
    $user   = "pejman";
    $server = "sshserver";
    $fp     = fsockopen($ip, $port);
    $str    = "/usr/bin/ssh -L ${port}:${ip}:${port} ${user}@${server} -N &";
    if($fp):
        fclose($fp);
    else:
        exec($str);
    endif;
    ? >

# chmod +x /usr/local/sbin/ssh-tunnel.php
# vi /etc/crontab
    *       *       *       *       *       root    /usr/local/sbin/ssh-tunnel.php > /dev/null

BY: Pejman Moghadam
TAG: ssh, freebsd
DATE: 2009-05-06 14:15:26


Pejman Moghadam / General [ TXT ]