[SOLVED] Autostart ssh server on LM 18

Connection sharing, Firewall, Samba..etc
Forum rules
Before you post please read how to get help
Post Reply
fabien85
Level 7
Level 7
Posts: 1584
Joined: Tue Mar 11, 2014 4:30 pm

[SOLVED] Autostart ssh server on LM 18

Post by fabien85 » Wed Jan 11, 2017 1:16 pm

Hi,
I have LM18.1 Mate on a small box (inxi output below), that I want to ssh to. I installed openssh etc, all is working well.
Except that it does not automatically start after login. I have to manually run sudo service ssh start everytime (after that, it works).
I googled a bit and tried some solutions :
- I added "sudo service ssh start" to /etc/rc.local.
- ran sudo systemctl enable ssh.socket from http://askubuntu.com/questions/3913/sta ... er-on-boot, which is supposed to work with systemd that LM18 uses
- ran sudo update-rc.d ssh defaults, from the same askubuntu page, which apparently only works with sysV (I guess this is the previous startup system, I dont know much about this stuff)

I also looked at /etc/network/if-up.d and there is indeed an entry called openssh-server with permissions rwxr-xr-x as the other entries there, so looks good to me. As much as I can decipher the content, I understand it's indeed supposed to put ssh up and running.

I dont know what gets wrong.

Code: Select all

~ $ inxi -Fxz
System:    Host: fabien-HP-Compaq-dc7600-Small-Form-Factor Kernel: 4.4.0-53-generic x86_64 (64 bit gcc: 5.4.0)
           Desktop: MATE 1.16.1 (Gtk 3.18.9-1ubuntu3.1) Distro: Linux Mint 18.1 Serena
Machine:   System: Hewlett-Packard product: HP Compaq dc7600 Small Form Factor
           Mobo: Hewlett-Packard model: 09F8h Bios: Hewlett-Packard v: 786D1 v01.03 date: 05/18/2005
CPU:       Single core Intel Pentium 4 (-HT-) cache: 2048 KB flags: (lm nx sse sse2 sse3) bmips: 6379 
           clock speeds: max: 3200 MHz 1: 2800 MHz 2: 2800 MHz
Graphics:  Card: Intel 82945G/GZ Integrated Graphics Controller bus-ID: 00:02.0
           Display Server: X.Org 1.18.4 drivers: intel (unloaded: fbdev,vesa) Resolution: 1920x1080@60.00hz
           GLX Renderer: Mesa DRI Intel 945G GLX Version: 1.4 Mesa 11.2.0 Direct Rendering: Yes
Audio:     Card Intel NM10/ICH7 Family High Definition Audio Controller driver: snd_hda_intel bus-ID: 00:1b.0
           Sound: Advanced Linux Sound Architecture v: k4.4.0-53-generic
Network:   Card: Broadcom NetXtreme BCM5752 Gigabit Ethernet PCI Express driver: tg3 v: 3.137 bus-ID: 3f:00.0
           IF: enp63s0 state: up speed: 100 Mbps duplex: full mac: <filter>
Drives:    HDD Total Size: 80.0GB (12.1% used) ID-1: /dev/sda model: SAMSUNG_HD080HJ size: 80.0GB
Partition: ID-1: / size: 71G used: 7.0G (11%) fs: ext4 dev: /dev/dm-1
           ID-2: /boot size: 472M used: 164M (37%) fs: ext2 dev: /dev/sda1
           ID-3: swap-1 size: 2.13GB used: 0.04GB (2%) fs: swap dev: /dev/dm-2
RAID:      No RAID devices: /proc/mdstat, md_mod kernel module present
Sensors:   None detected - is lm-sensors installed and configured?
Info:      Processes: 194 Uptime: 57 min Memory: 639.4/1991.9MB Init: systemd runlevel: 5 Gcc sys: 5.4.0
           Client: Shell (bash 4.3.461) inxi: 2.2.35
Last edited by fabien85 on Thu Jan 19, 2017 7:51 am, edited 1 time in total.

User avatar
txba516
Level 3
Level 3
Posts: 197
Joined: Fri Aug 10, 2007 11:57 am
Location: Atlanta, GA

Re: Autostart ssh server on LM 18

Post by txba516 » Wed Jan 11, 2017 2:23 pm

It looks like you nearly got it with the Systemd command except you enabled the socket and not the service. Try

Code: Select all

sudo systemctl enable ssh.service
Cheers!
LM17.2 x64 Cinnamon
Help the forums get answers faster! Mark your fixed problem thread as [SOLVED]

fabien85
Level 7
Level 7
Posts: 1584
Joined: Tue Mar 11, 2014 4:30 pm

Re: Autostart ssh server on LM 18

Post by fabien85 » Thu Jan 12, 2017 10:36 am

Thanks, but it didnt work.
As a result of the command, I got :

Code: Select all

~ $ sudo systemctl enable ssh.service
[sudo] password for fabien: 
Synchronizing state of ssh.service with SysV init with /lib/systemd/systemd-sysv-install...
Executing /lib/systemd/systemd-sysv-install enable ssh
~ $
which I guess is good, or maybe it means I use sysV instead of systemd ? I'm confused and dont know anything about this.

Anyway, I rebooted (cold shutdown+reboot) twice, and it's not working, I still have to sudo service ssh start.
I tried combining this with 'sudo service ssh start' in /etc/rc.local, but it didnt work either.

If that changes anything, I have full disk encryption, I changed the port to which ssh listens, put up gufw and allowed that port.
(but everything works after I manually start the ssh service)

altair4
Level 19
Level 19
Posts: 9755
Joined: Tue Feb 03, 2009 10:27 am

Re: Autostart ssh server on LM 18

Post by altair4 » Thu Jan 12, 2017 12:32 pm

I have no experience with your particular problem but you need to stop doing this:
I tried combining this with 'sudo service ssh start' in /etc/rc.local, but it didnt work either.
Take out the sudo. rc.local is run by root. Adding sudo will cause it to fail.
Please add a [SOLVED] at the end of your original subject header if your question has been answered and solved.

deleted

Re: Autostart ssh server on LM 18

Post by deleted » Thu Jan 12, 2017 5:31 pm

This is really odd.
I've never had to do anything except install ssh-server and it just started automatically.
-H

fabien85
Level 7
Level 7
Posts: 1584
Joined: Tue Mar 11, 2014 4:30 pm

Re: Autostart ssh server on LM 18

Post by fabien85 » Fri Jan 13, 2017 9:44 am

Thanks for the replies guys.
I started from scratch, disabling ufw, going back to the default port 22, removing sudo in my command in /etc/rc.local
After many shutdowns reboots and tries, I have come to the conclusion that :
- the line in /etc/rc.local is unnecessary, corroborating hinto.
- it works perfectly on port 22
- if I use another port, it doesnt work by default, I have to manually run 'sudo service ssh start' after login

I originally wanted to change the default port to follow http://linuxlookup.com/howto/change_default_ssh_port

Now I'm a bit ignorant in terms of network security etc, so maybe changing port is not that much of an improvement.
I disabled password authentication, and that may be a better security measure.

I'm ok with staying on port 22 and calling this solved.
However gufw states that "It may be a security risk to use a default allow policy for SSH". Do you have good advices for improving the security ? (or pointers as to where to get advices)

Thanks

User avatar
txba516
Level 3
Level 3
Posts: 197
Joined: Fri Aug 10, 2007 11:57 am
Location: Atlanta, GA

Re: Autostart ssh server on LM 18

Post by txba516 » Fri Jan 13, 2017 4:43 pm

All that GUFW is implying by that warning is that it may be a less than great idea to have SSH open to the entire Internet (allow from anywhere). GUFW would prefer you restricted who can reach the SSH port by defining an explicit source IP or network that is allowed to connect.
You have greatly improved things by removing the password authentication. Hopefully you are doing auth by key pairs instead?
LM17.2 x64 Cinnamon
Help the forums get answers faster! Mark your fixed problem thread as [SOLVED]

BradW
Level 1
Level 1
Posts: 11
Joined: Sat Jan 14, 2017 1:58 am

Re: Autostart ssh server on LM 18

Post by BradW » Sat Jan 14, 2017 2:11 am

I just installed Mint 18.1 and openssh-server. I am getting an error:

systemctl start ssh
Failed to start ssh.service: Unit ssh.service is masked.

Anyone have any idea why this is happening?

Thanks for the help!

Brad

Laurent85
Level 16
Level 16
Posts: 6148
Joined: Tue May 26, 2015 10:11 am

Re: Autostart ssh server on LM 18

Post by Laurent85 » Sat Jan 14, 2017 5:53 am

Provide the logs and systemctl status for ssh:

Code: Select all

systemctl status ssh
sudo grep ssh /var/log/auth.log | tail -30
Image

altair4
Level 19
Level 19
Posts: 9755
Joined: Tue Feb 03, 2009 10:27 am

Re: Autostart ssh server on LM 18

Post by altair4 » Sat Jan 14, 2017 8:18 am

Failed to start ssh.service: Unit ssh.service is masked.
What in the world is happening to ssh in Mint18?

If it's masked you cannot start it so unmask it:

Code: Select all

sudo systemctl unmask ssh
Just in case make sure it's enabled:

Code: Select all

sudo systemctl enable ssh
Then restart it:

Code: Select all

sudo systemctl restart ssh
Please add a [SOLVED] at the end of your original subject header if your question has been answered and solved.

fabien85
Level 7
Level 7
Posts: 1584
Joined: Tue Mar 11, 2014 4:30 pm

Re: Autostart ssh server on LM 18

Post by fabien85 » Sat Jan 14, 2017 1:20 pm

txba516 wrote:Hopefully you are doing auth by key pairs instead?
Do you mean authentication by RSA public/private key ?
That's what I did, putting in .ssh/authorized_keys the public key of each computer I want to connect with.

I think the thread is solved for me. Since there is another question, I will leave it open for the moment.

BradW
Level 1
Level 1
Posts: 11
Joined: Sat Jan 14, 2017 1:58 am

Re: Autostart ssh server on LM 18

Post by BradW » Wed Jan 18, 2017 7:12 pm

I unmasked ssh, but still can't connect. :(

Here's the outputs requested:

sookie log # grep ssh /var/log/auth.log | tail -30
Jan 18 15:04:31 sookie sudo: root : TTY=pts/1 ; PWD=/var/log ; USER=root ; COMMAND=/bin/grep ssh /var/log/auth.log
Jan 18 15:05:17 sookie sudo: root : TTY=pts/1 ; PWD=/var/log ; USER=root ; COMMAND=/bin/grep ssh /var/log/auth.log

sookie log # systemctl status ssh
● ssh.service - LSB: OpenBSD Secure Shell server
Loaded: loaded (/etc/init.d/ssh; bad; vendor preset: enabled)
Active: active (exited) since Wed 2017-01-18 15:05:13 PST; 3min 34s ago
Docs: man:systemd-sysv-generator(8)
Process: 32150 ExecStop=/etc/init.d/ssh stop (code=exited, status=0/SUCCESS)
Process: 32153 ExecStart=/etc/init.d/ssh start (code=exited, status=0/SUCCESS)

Jan 18 15:05:13 sookie systemd[1]: Starting LSB: OpenBSD Secure Shell server...
Jan 18 15:05:13 sookie systemd[1]: Started LSB: OpenBSD Secure Shell server.

Unfortunately:

sookie log # ssh localhost
ssh: connect to host localhost port 22: Connection refused

Thanks for the help!

Brad

BradW
Level 1
Level 1
Posts: 11
Joined: Sat Jan 14, 2017 1:58 am

[UPDATE] Re: Autostart ssh server on LM 18

Post by BradW » Thu Jan 19, 2017 1:05 am

After Googling further, I found a post recommending the following:

apt-get install ssh

Voila! This solved it! Things are working as expected now. :)

Thanks to everyone for the help!

Brad

Post Reply

Return to “Other networking topics”