sshd_config通过systemd进行更改

问题描述 投票:0回答:1

我正在尝试在Raspberry Pi上运行Ubuntu的首次启动时自动执行一些任务。我有一个Systemd服务,该服务运行一次并杀死自己。作为它的一部分,我正在尝试更新sshd_config上的配置,并尝试了所有我能想到的可能并在Google上搜索但徒劳的方法。希望有人可以在这里有更多处理此类内容的经验。

# disable password login
echo "First Boot - disabling ssh password login"
sed -i 's/PasswordAuthentication.*/PasswordAuthentication no/' /etc/ssh/sshd_config

Systemctl和Syslog在执行中不显示任何错误。如果我在命令行上运行上述命令,则其行为将与预期的一样。

我尝试过的其他方法

Attempt 1: Assuming permission errors due to in-place sed file creation. I have routed the output to a temp file on printing the contents it looks right but the actual location i.e. /etc/ssh/sshd_config has no changes

TFILE=`mktemp --tmpdir tfile.XXXXX`
trap `rm -f $TFILE` 0 1 2 3 15
sed 's/PasswordAuthentication.*/PasswordAuthentication no/' /etc/ssh/sshd_config > $TFILE
cat $TFILE > /etc/ssh/sshd_config

Attempt 2: Read somewhere that /etc/ssh/sshd_config is a symlink to file in /usr and get copied over and hence executing first line copies it to /etc and changes on top 

sed -i '' /etc/ssh/sshd_config
sed -i 's/PasswordAuthentication.*/PasswordAuthentication no/' /etc/ssh/sshd_config

更新23/02:

服务文件

[Unit]
Description=First boot script
ConditionPathExists=/first_boot.sh

[Service]
Type=oneshot
RemainAfterExit=true
ExecStart=/first_boot.sh
StandardOutput=journal+console

[Install]
WantedBy=multi-user.target
ubuntu raspberry-pi systemd sshd
1个回答
0
投票

检查“ nologin”-http://man7.org/linux/man-pages/man8/nologin.8.html简单易用:触摸/ etc / nologin;然后是rm -f / etc / nologin。

© www.soinside.com 2019 - 2024. All rights reserved.