我将/etc/ssh/sshd_config
的端口更改为23.我重新启动了sshd(sudo systemctl restart sshd
)。我为23添加了防火墙规则:
gcloud compute firewall-rules create debug-ssh-23 --allow tcp:23
但仍然没有工作...... Ssh命令超时。如何正确更改sshd
端口?
编辑:
防火墙规则是:
{
"allowed": [
{
"IPProtocol": "tcp",
"ports": [
"23"
]
}
],
"creationTimestamp": "2018-10-02T14:02:23.646-07:00",
"description": "",
"direction": "INGRESS",
"disabled": false,
"id": "3968818270732968496",
"kind": "compute#firewall",
"name": "debug-ssh-23",
"network": "https://www.googleapis.com/compute/v1/projects/foo/global/networks/default",
"priority": 1000,
"selfLink": "https://www.googleapis.com/compute/v1/projects/foo/global/firewalls/debug-ssh-23",
"sourceRanges": [
"0.0.0.0/0"
]
}
但我无法在此端口上访问简单的nginx服务。 80年代,作品。 80的规则是相似的。
sshd_config中:
# Force protocol v2 only
Protocol 2
# Disable IPv6 for now
AddressFamily inet
# /etc is read-only. Fetch keys from stateful partition
# Not using v1, so no v1 key
HostKey /mnt/stateful_partition/etc/ssh/ssh_host_rsa_key
HostKey /mnt/stateful_partition/etc/ssh/ssh_host_ed25519_key
PasswordAuthentication no
ChallengeResponseAuthentication no
PermitRootLogin no
UsePAM yes
PrintMotd no
PrintLastLog no
UseDns no
Subsystem sftp internal-sftp
PermitTunnel no
AllowTcpForwarding yes
X11Forwarding no
Ciphers [email protected],[email protected],[email protected],aes128-ctr,aes192-ctr,aes256-ctr
# Compute times out connections after 10 minutes of inactivity. Keep alive
# ssh connections by sending a packet every 7 minutes.
ClientAliveInterval 420
AcceptEnv EDITOR LANG LC_ALL PAGER TZ
除了sshd_config
选项Port
,也见ListenAddress
运行sudo systemctl reload sshd.service
来应用更改。
你需要添加选项ssh-flag
才能连接到另一个端口:
gcloud compute --project "PROJECT_NAME" ssh --zone "us-central1-b" "instance-1" --ssh-flag="-p 23"
在云控制台中,还有“在自定义端口上的浏览器窗口中打开”。
看,听到的时间和地点......
sudo cat /var/log/secure | grep sshd
输出应该看起来像这样:
instance-1 sshd[1192]: Server listening on 0.0.0.0 port 23.
instance-1 sshd[1192]: Server listening on :: port 23.
我不需要将ssh-flag添加到我的gcloud命令(我可以查看但无法弄清楚如何编辑)。我按照这些说明操作:
Using SSH through airplane WiFi that blocks port 22
但我的Centos安装有一个空白的sshd_config。我只是添加了这一行:
Port 80
并跑了(我先在上面的链接中执行了命令):
systemctl restart sshd.service
然后我在端口80上运行SSHD。
其他注意事项:
#Port 22
至:
Port 80
并且还在我的帖子中执行了第一个链接中的所有命令。