Anyone know if I can enable a service from autoinstall? I’m installing openssh-server in the autoinstall, and I’d like it to start on first boot after the install is done. Can it be done with autoinstall/cloud-init?
@jby you have another thread here:Enable/start service in autoinstall/cloud-init?
Which has a reply. Have you seen that yet?
Yes, it has a reply, but none that solves the problem - it did however give something to try.
No answer to my question though?
I’m not trying to sound codensending but this is still rather vauge to me anyway.
If you use an autoinstall configuration like this example:
#cloud-config
autoinstall:
packages:
- cowsay
user-data:
packages:
- rolldice
The package cowsay will be installed during the installation. The package rolldice will be installed by cloud-init during first boot. (Unless things have changed that I’m not aware of)
Note, cowsay and rolldice are just small test apps for an example only.
This file:
less /etc/cloud/cloud.cfg.d/99-installer.cfg
More Information here: https://documentation.ubuntu.com/lxd/en/latest/cloud-init/
Hope that helps.
So, here is my complete autoinstall file:
#cloud-config
autoinstall:
version: 1
source:
id: ubuntu-desktop-minimal
network:
ethernets:
dhcp4: true
locale: en_US.UTF-8
keyboard:
layout: sv
timezone: Europe/Stockholm
interactive-sections:
- storage
- identity
ssh:
install-server: true
allow-pw: true
authorized-keys: []
packages:
- git
- ansible
- cifs-utils
- curl
- dkms
- keyutils
- krb5-user
- landscape-client
- libdrm-dev
- libnss3-tools
- libqt5webkit5
- openssh-server
- ufw
- vim-nox
shutdown: reboot
After reboot sshd is not enabled…
Even if I add this:
ssh:
install-server: true
allow-pw: true
authorized-keys: []
sshd is not enabled after boot…
Will this not work?`
sudo nano /etc/ssh/sshd_config
I’ve changed the port it listens on.
# For changes to take effect, run:
#
# systemctl daemon-reload
# systemctl restart ssh.socket
#
**Port 2024**
#AddressFamily any
#ListenAddress 0.0.0.0
Also need to tell UFW about the change
sudo ufw allow 2024
Then reload ufw
sudo ufw reload
Should be good, as long as SSH is started and enabled
sudo systemctl enable ssh
` sudo systemctl start ssh
`
Now check SSh status
systemctl status ssh
● ssh.service - OpenBSD Secure Shell server
Loaded: loaded (/usr/lib/systemd/system/ssh.service; enabled; preset: enabled)
Active: active (running) since Tue 2024-11-26 12:41:22 MST; 44s ago
Invocation: 87b13a7457c64d87834e1d9a4b5b33fd
TriggeredBy: ● ssh.socket
Docs: man:sshd(8)
man:sshd_config(5)
Main PID: 23588 (sshd)
Tasks: 1 (limit: 4597)
Memory: 1.5M (peak: 2.1M)
CPU: 24ms
CGroup: /system.slice/ssh.service
└─23588 "sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups"
Nov 26 12:41:22 me-Standard-PC-Q35-zfs systemd[1]: Starting ssh.service - OpenBSD Secure Shell server...
Nov 26 12:41:22 me-Standard-PC-Q35-zfs sshd[23588]: Server listening on 0.0.0.0 port 22.
Nov 26 12:41:22 me-Standard-PC-Q35-zfs sshd[23588]: Server listening on :: port 22.
Nov 26 12:41:22 me-Standard-PC-Q35-zfs systemd[1]: Started ssh.service - OpenBSD Secure Shell server.
Try adding to your YAML:
runcmd:
- [ systemctl, enable, ssh ]
Why would I want to start my sshd on port 2024? And if I’m to enable and start it manually as you suggest - why would I even ask the question on how to enable it from autoinstall?
I’ll test this tomorrow, thanks!
Ok, @ian-weisser & @1fallen - I’ve now done some further testing.
-
Adding a
user-data
section does not help - it does install at first reboot, but for some reason leaves ssh disabled… -
Using
runcmd
(and the service isssh
notsshd
) does not help -
Using a
late-command
withcurtin-in-target
to enable ssh fails with anon-zero exit status
So, it seems manual enable after first boot is my only option…
I have a lot of posts I’ve gathered through out many years, I move them to a storage tank, And unfortunately the links get lost or a no longer a valid URL.
My apologies that that was not complete enough for you here .
Perhaps you could provide that link if you feel it’s useful.
I see a lot of mine that I’ve helped others with, with no mention or links to.
At the end of the day, it’s all about a solution and not so much about credit.
I as well could never with autoinstall get SSH to autostart.
You could have started with this, then maybe I wouldn’t have had to spend two days with different incantations in my autoinstall.yaml to try to get it to work…
It’s a bit strange though, because if you install it from the command line in a fully installed system it enables itself upon install…
I did, in my reply to you
Just because you or I couldn’t, doesn’t mean it’s not a possibility.
Well I guess I owe both of us some wasted time back.
I hope you sort this out,and best of luck.
Yeah, well - we’ll see. I’ll update my colleagues with the info that they’ll have to manually start sshd if they want to use it during the finalization of the install process.
Still, it’s strange…
No, I probably would have spent time on it anyway. I don’t like unambiguity like this when it comes to computers…
for some background see:
Ok, didn’t know that.
I’ll test when I’m back in the office after the holidays.
Thanks!