Reverse ssh

Discuss how to write good code, break bad code, your current pet projects, or the best way to approach novel problems

Reverse ssh

Post by NkC3ll on Tue Jan 29, 2013 2:27 pm
([msg=72899]see Reverse ssh[/msg])

Hello guys,

I'm trying to write reverse ssh tunneling, but for some reason it doesn't run well !

If Someone know how to make right this sort of script, please help !

Thanks a lot ! :)
NkC3ll
New User
New User
 
Posts: 4
Joined: Tue Jan 29, 2013 2:22 pm
Blog: View Blog (0)


Re: Reverse ssh

Post by fashizzlepop on Tue Jan 29, 2013 2:39 pm
([msg=72902]see Re: Reverse ssh[/msg])

Post your code (in a gist or pastebin please) and we can look over it for you.
The glass is neither half-full nor half-empty; it's merely twice as big as it needs to be.
User avatar
fashizzlepop
Developer
Developer
 
Posts: 2303
Joined: Sat May 24, 2008 1:20 pm
Blog: View Blog (0)


Re: Reverse ssh

Post by NkC3ll on Tue Jan 29, 2013 4:35 pm
([msg=72909]see Re: Reverse ssh[/msg])

Code: Select all
#!/bin/sh

REMOTE_HOST='the remote host'
PASS='the remote password'
REMOTE_PORT=5000

# $COMMAND is the command used to create the reverse ssh tunnel
COMMAND="ssh -q -N -R $REMOTE_PORT:localhost:22 the-remote-username@$REMOTE_HOST"

# Is the tunnel up? Perform two tests:

# 1. Check for relevant process ($COMMAND)
pgrep -f -x "$COMMAND" > /dev/null 2>&1 || $COMMAND

# 2. Test tunnel by looking at "netstat" output on $REMOTE_HOST
ssh $REMOTE_HOST netstat -an | egrep "tcp.*:$REMOTE_PORT.*LISTEN" > /dev/null 2>&1

if [ $? -ne 0 ] ; then
   pkill -f -x "$COMMAND"
   $COMMAND
fi


-- Wed Jan 30, 2013 12:24 pm --

fashizzlepop i have post it ...

Did you found the wrong syntax ??


Please help !
NkC3ll
New User
New User
 
Posts: 4
Joined: Tue Jan 29, 2013 2:22 pm
Blog: View Blog (0)



Return to Programming

Who is online

Users browsing this forum: No registered users and 0 guests

cron