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 -L -N


ssh -L -D -N

SSH CallBack

ssh user@ -R 2222: -N

Automatic ssh tunnel (freebsd)


# 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

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


# vi /etc/hosts          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/
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/ pejman@sshserver
or :
 # scp /root/.ssh/ 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
    < ? php
    $port   = 5000;
    $ip     = "localhost";
    $user   = "pejman";
    $server = "sshserver";
    $fp     = fsockopen($ip, $port);
    $str    = "/usr/bin/ssh -L ${port}:${ip}:${port} ${user}@${server} -N &";
    ? >

# 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 ]