大网数据广告活动
服务器运维问答

How to temporarily run a secondary SSH server on a separate port

· 52CE 我爱测

How do you run an SSH daemon on a different port other than the standard 22? I screwed up something with my SSH configuration on a cloud VM, so that now SSH always prompts me for a password. My early attempts to fix this locked m…

问题原文

原帖链接 · Cerin · CC BY-SA 3.0

How do you run an SSH daemon on a different port other than the standard 22?

I screwed up something with my SSH configuration on a cloud VM, so that now SSH always prompts me for a password. My early attempts to fix this locked me out, forcing me to umount the disk, mount it inside a working VM, and fix the files to a known working state. However, it's still forcing me to enter a password.

I'd like to update my /etc/ssh/sshd_config and restart the main ssh daemon, which I can test against, while still having another one running, using the old configuration, that I can use to revert the configuration in case the first one locks me out. How would I do this, specifically on Ubuntu?

社区高分解答

原帖链接 · Zoredache · CC BY-SA 3.0

You didn't mention an Ubuntu version, so I am not sure which init system you are running.

If systemd, you may have a file /etc/systemd/system/sshd.service. Which you could make a copy of as /etc/systemd/system/sshd_alt.service. Then adjust the ExecStart line and add a -p 22000 or something. After that do systemctl enable sshd_alt and systemctl start sshd_alt. You could also point at a completely different configuration file.

You could also just manually start a copy in screen or something if this is just a one time thing. Just start screen and do something like /usr/sbin/sshd -D -p 22200. You will start a spare sshd daemon until you can re-attach to that screen and kill the process.

Or like @EEAA said. Simply don't disconnect, use a second session to test that you can reconnect.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-01-17)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。