使用最新的Ubuntu版本,常规修改ssh端口,但是发现根据常规方法修改 sshd_config
无效,所以记录本次的可行方案。
原因
As of version 1:9.0p1-1ubuntu1 of
openssh-server
in Kinetic Kudu (Ubuntu 22.10), OpenSSH in Ubuntu is configured by default to use systemd socket activation. This means that sshd will not be started until an incoming connection request is received. This has been done to reduce the memory consumed by Ubuntu Server instances by default, which is of particular interest with Ubuntu running in VMs or LXD containers: by not running sshd when it is not used, we save at least 3MiB of memory in each instance, representing a savings of roughly 5% on an idle, pristine kinetic container.
相关链接:https://discourse.ubuntu.com/t/sshd-now-uses-socket-based-activation-ubuntu-22-10-and-later/30189
分析
意思就是22.10之后的版本使用方式不一样了,sshd 的监听任务就转交给了 ssh socket
,修改 sshd_config
中的端口无效。
注意:此版本后,sshd
的服务名变成了ssh
。(程序名没变)
解决
vi /etc/ssh/sshd_config
# 执行下面的命令,修改 ListenStream= 后面的端口号。
vi /usr/lib/systemd/system/ssh.socket
# 重载配置
systemctl daemon-reload
# 重启 socket
systemctl restart ssh.socket
# 测试
ssh $USER@localhost -p 22666
具体请参考:https://bugs.launchpad.net/ubuntu/+source/openssh/+bug/2069041
到此为止,应该能解决你的问题了,希望本文能帮助到你。
评论