Answer the question
In order to leave comments, you need to log in
Why doesn't autoload work in linux (other ways to autostart ssh tunnel)?
Hello. I am familiar with Linux for the fourth day, I hate it. I hate it when everything should work, but for some reason it doesn't. However, I did everything I needed to and stopped one step away from the task.
It is necessary to execute the command automatically at system startup (connect to the server via ssh).
1. To do this, I created a script in init.d according to the sample
sudo cp /etc/init.d/skeleton /etc/init.d/myscript && vi /etc/init.d/myscript
2. Edited it, it turned out like this ( the script runs when I run /etc/init.d/myscript start):
#! /bin/sh
### BEGIN INIT INFO
# Provides: ssh
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Example initscript
# Description: This file should be used to construct scripts to be
# placed in /etc/init.d.
### END INIT INFO
# Author: Foo Bar <[email protected]>
. /lib/lsb/init-functions
# Function that starts the daemon/service
perform_start()
{
log_daemon_msg "start tunnel"
sleep 20 && ssh [email protected]5X.2XX.1XX.9X -R 5544:localhost:22 -i ~/.ssh/mykeys.pem
return 0
}
# Function that stops the daemon/service
perform_stop()
{
log_daemon_msg "navernoe ne nuzhno"
}
case "$1" in
start)
perform_start
;;
stop)
perform_stop
;;
*)
echo "Usage: /etc/init.d/mysc {start|stop}"
exit 3
;;
esac
:
Answer the question
In order to leave comments, you need to log in
Report for lovers of detectives. Sherlock is resting.
In general, the system does not start. Either it starts or it doesn’t start, depending on how many seconds you choose to boot into the countdown.
Started in failsafe mode. I connect via ssh through the terminal to the server - it connects. Now, through port 5544 from my home computer, I connect through this server to the one on which the witchcraft was discussed here. And I get connection refused, although before everything was always connected without problems.
I go back to the object of witchcraft and notice that in the terminal, before connecting to the server, there is a message that nothing passes through port 5544. Attention, the moment of autumn. I understand that port 5544 is already in use. But I removed everything in crontab! So what about the port? Well, it's already in use! So the original script worked all this time! I thought that if the script works, then a terminal window with a connected server should pop up on the desktop. But it turns out that all this is happening somewhere in the background (right now I don’t understand how I can get into this terminal if it starts in the background, it’s good that I don’t need it). This is where things begin to unravel, I understand that the problems with booting the system were due to the autossh startup interval of 20 seconds. Those. if I had time to quickly enter the system, then it loaded, if I waited 5 seconds,
And now another joke. From crontab, when the system boots, my script does not appear to be executed, but another program (btsync) is executed. I did not know this and therefore decided that this method suits me. At the same time, via ssh, the connection was made from a script from init.d via update-rc.d autoload.
That's it.
-i ~/.ssh/mykeys.pem
You can add to /etc/crontab (possibly also using the crontab -e command) the line:
@reboot root /etc/init.d/myscript
use "root" as the path to the script, at your discretion.
If by the time the cron starts something else has not had time to load, you can do this:
@reboot root sleep 60 && /etc/init.d/myscript
There is a problem in ~/ hike, either write the absolute path, or put the command somewhere here: rus-linux.net/MyLDP/consol/hdrguide/rusman/profile.htm
The last tip helped. Thanks i_maltsev ! I thought a terminal window would pop up and everything would happen in the usual way. Therefore, I spent a lot of time figuring out which of the tips helped me.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question