如何更改google云实例上的ssh端口?

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

我将/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
google-cloud-platform google-compute-engine
2个回答
2
投票

除了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.

0
投票

我不需要将ssh-flag添加到我的gcloud命令(我可以查看但无法弄清楚如何编辑)。我按照这些说明操作:

Using SSH through airplane WiFi that blocks port 22

但我的Centos安装有一个空白的sshd_config。我只是添加了这一行:

Port 80

并跑了(我先在上面的链接中执行了命令):

systemctl restart sshd.service

然后我在端口80上运行SSHD。

其他注意事项:

  1. 我使用这个是因为我想在JetBlue航班上工作而我无法使用SSH连接到我的服务器(似乎它们阻止了端口22流量,我不想更改我运行SSHD的端口)。所以,我创建了这个VM以在端口80上运行SSH,然后我可以从那里连接到我的服务器。
  2. 为了节省300美元的Google Cloud积分,我关闭了我的虚拟机实例,当我在飞机上时,我开启了它,并且Google Cloud Zone上没有足够的资源来启动我的实例。哎呀!在您离开航班之前将VM实例设置为运行,以确保它可以提前使用。将它移动到另一个区域是一个PITA,所以我创建了一个新实例,发现我可以连接到它,即使它设置为默认情况下通过gcloud控制台通过SSH在浏览器窗口中连接来连接到端口22上的SSH ,所以没有必要改变运行SSH的端口(至少对于JetBlue而言)......
  3. 当我使用CENTOS 7映像创建第二个VM实例时,这次它创建了一个完整的sshd_config文件,我刚刚更改了以下行:

#Port 22

至:

Port 80

并且还在我的帖子中执行了第一个链接中的所有命令。

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