You are not logged in.

#1 2013-02-04 23:43:30

miscsubbin
Member
Registered: 2012-10-30
Posts: 37

Starting SSH on boot?

I use ssh as a SOCKS proxy because it provides speed benefits at my university. Is there a way I can start this at boot? Here's the command:

ssh -D 7070 username@hostname

I've tried throwing this in my .xinitrc and backrounding it, along with putting it in my rc.lua (for awesome wm). Neither seem to work,  and ssh doesn't show up on a "ps -e" either. What could be the problem?

Offline

#2 2013-02-04 23:52:26

Ztjuh
Member
Registered: 2011-05-30
Posts: 58

Re: Starting SSH on boot?

Try putting it in a crontab with @reboot.

Offline

#3 2013-02-04 23:56:07

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,734
Website

Re: Starting SSH on boot?

Why not write a trivial mysocks.service that simply calls your one-line script?

[Unit]
Description=My script

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/local/bin/myscript

[Install]
WantedBy=multi-user.target

Offline

#4 2013-02-04 23:59:10

oliver
Member
Registered: 2007-12-12
Posts: 448

Re: Starting SSH on boot?

never mind...  better options given

Last edited by oliver (2013-02-05 00:00:42)

Offline

#5 2013-02-05 00:15:31

miscsubbin
Member
Registered: 2012-10-30
Posts: 37

Re: Starting SSH on boot?

graysky wrote:

Why not write a trivial mysocks.service that simply calls your one-line script?

[Unit]
Description=My script

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/local/bin/myscript

[Install]
WantedBy=multi-user.target

I've tried this solution (mainly because I knew how to do it), and it still is not working. I think part of the problem may be that I use a key generated from ssh-keygen to login without a password. If not run by the correct user, it wouldn't work. Could that be the problem, and how would I resolve it?

EDIT: Didn't look closely at the error message. It says that it failed to start, and upon checking the status, it says

Loaded: error (Reason: No such file or directory)

which is strange because everything involved should exist.

Last edited by miscsubbin (2013-02-05 00:22:43)

Offline

#6 2013-02-05 05:36:13

roentgen
Member
Registered: 2011-03-15
Posts: 91

Re: Starting SSH on boot?

miscsubbin wrote:

I think part of the problem may be that I use a key generated from ssh-keygen to login without a password. If not run by the correct user, it wouldn't work. Could that be the problem, and how would I resolve it?

Then ssh needs to be executed as your username.
Try putting "User=your_user" in the [Service] section.

Offline

#7 2013-02-05 14:41:06

miscsubbin
Member
Registered: 2012-10-30
Posts: 37

Re: Starting SSH on boot?

roentgen wrote:
miscsubbin wrote:

I think part of the problem may be that I use a key generated from ssh-keygen to login without a password. If not run by the correct user, it wouldn't work. Could that be the problem, and how would I resolve it?

Then ssh needs to be executed as your username.
Try putting "User=your_user" in the [Service] section.

Even with this it still gives a "No such file or directory" error when I use

systemctl status ssh-python.service

I have no idea why. Everything appears to be set up correctly. The script works, and is in the path specified in the .service file. The service is in "$HOME/.config/systemd/user/ssh-socks.service" and the script is in "/usr/local/bin/ssh-socks", and has correct permissions.

Offline

#8 2013-02-05 14:48:39

65kid
Member
From: Germany
Registered: 2011-01-26
Posts: 663

Re: Starting SSH on boot?

miscsubbin wrote:
roentgen wrote:
miscsubbin wrote:

I think part of the problem may be that I use a key generated from ssh-keygen to login without a password. If not run by the correct user, it wouldn't work. Could that be the problem, and how would I resolve it?

Then ssh needs to be executed as your username.
Try putting "User=your_user" in the [Service] section.

Even with this it still gives a "No such file or directory" error when I use

systemctl status ssh-python.service

I have no idea why. Everything appears to be set up correctly. The script works, and is in the path specified in the .service file. The service is in "$HOME/.config/systemd/user/ssh-socks.service" and the script is in "/usr/local/bin/ssh-socks", and has correct permissions.

$HOME/.config/systemd/user/ is for systemd user sessions (which I assume you are not running). You have to put the service file in /etc/systemd/system/.

Offline

#9 2013-02-05 15:15:23

miscsubbin
Member
Registered: 2012-10-30
Posts: 37

Re: Starting SSH on boot?

OK, now it doesn't throw an error, but I can't seem to access it. And "ps -e" doesn't show an instance of it running.

Offline

#10 2013-02-05 15:38:32

65kid
Member
From: Germany
Registered: 2011-01-26
Posts: 663

Re: Starting SSH on boot?

miscsubbin wrote:

OK, now it doesn't throw an error, but I can't seem to access it. And "ps -e" doesn't show an instance of it running.

check the "systemctl status" output. Type=oneshot may be wrong, you may have to use Type=forking or Type=simple, depending on what the process does.

Offline

#11 2013-02-05 22:19:30

miscsubbin
Member
Registered: 2012-10-30
Posts: 37

Re: Starting SSH on boot?

ssh-python.service - Login to HOSTNAME for use as a SOCKS proxy
	  Loaded: loaded (/etc/systemd/system/ssh-python.service; enabled)
	  Active: active (exited) since Tue 2013-02-05 10:10:06 EST; 7h ago
	 Process: 4432 ExecStart=/usr/local/bin/ssh-python (code=exited, status=0/SUCCESS)

Looks like it succeeds then closes. Any way to keep it open?

Offline

Board footer

Powered by FluxBB