Link to home
Start Free TrialLog in
Avatar of AXISHK
AXISHK

asked on

ssh forwarfing start as daemon

Does anyone have experience of configuring I ssh forwarding as daemon in linux ? pls share your configuration
Avatar of Steven Vona
Steven Vona
Flag of United States of America image

ssh forwarding is not a daemon.  There is no configuration that I know of in the SSH daemon to automatically bring up a tunnel or forwarding.

Also, when you start forwarding a port from one system to another (I am assuming that is what your doing) it is user done as a user.

Can you give an example of what your trying to do?  Also make sure to give more details in all your questions, it will help us help you. (example: what flavor/version of Linux your using, what you are trying to accomplish, what you tried already, etc...)
Avatar of AXISHK
AXISHK

ASKER

I'm running Redhat 5.

There are two servers,  
      ServerA     -->   ServerB (MySQL server)

I want to put this to run everything when the server boot up.
ssh -fNg -L 3306:localhost:3306 sciadm@mysqlserver

I try autossh but it doesn't work.

Tks
You can create an init script and place it in /etc/init.d/

Once you've created a script, named forwardssh in this,

    Enable the script

     chkconfig --add forwardssh
     chkconfig --level 2345 forwardssh on

    Check the script is indeed enabled - you should see "on" for the levels you selected.

     chkconfig --list | grep forwardssh




Taken from a site I can't link to here. /questions/20357/how-can-i-make-a-script-in-etc-init-d-start-at-boot

#!/bin/bash
# chkconfig: 2345 20 80
# description: Description comes here....

# Source function library.
. /etc/init.d/functions

start() {
    # code to start app comes here 
    # example: daemon program_name &
}

stop() {
    # code to stop app comes here 
    # example: killproc program_name
}

case "$1" in 
    start)
       start
       ;;
    stop)
       stop
       ;;
    restart)
       stop
       start
       ;;
    status)
       # code to check status of app comes here 
       # example: status program_name
       ;;
    *)
       echo "Usage: $0 {start|stop|status|restart}"
esac

exit 0 

Open in new window

Google for "place a script in init.d"

You could make it really simple and not check anything, but you'll have problems later when you want to control the startup through the script.
#!/bin/bash
ssh -fNg -L 3306:localhost:3306 sciadm@mysqlserver
Avatar of AXISHK

ASKER

To clarify, I create a file under /etc/init.d/forwardssh  and put my script here.

Afterwards, chkconfig --add forwardssh

Do I need to specifyc a full path, or linux can find it when adding under /etc/init.d  ?

for chkconfig --level 2345 forwardssh on , will that mean linux will create the symbolic link such as the following,  
  /etc/rc0.d/K20blah -> /etc/rc.d/init.d/blah
   /etc/rc1.d/K20blah ->  /etc/rc.d//init.d/blah

or
Do I l need to create a link ? Is it a hard or soft link ?  Tks
You should not have to do anything further.  You can check that it was added with the following command.

 chkconfig --list | grep -i forwardssh
ASKER CERTIFIED SOLUTION
Avatar of serialband
serialband
Flag of Ukraine image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of AXISHK

ASKER

Tks