Ubuntu SSH IP 地址问题

Ubuntu SSH IP 地址问题

我计划使用新购买的台式机作为服务器,我想先设置 SSH 服务。到目前为止,我还没有成功,我认为问题在于我的电脑 IP 由我居住的公寓大楼控制,因此我似乎对端口绑定的控制受到限制(即没有控制)。

有没有什么办法可以解决这个问题?

(注:我还在不断学习,因此如果您在回答中提供任何即兴的建议,我将不胜感激!)

编辑1:

sshd_config

# Package generated configuration file
# See the sshd_config(5) manpage for details

# What ports, IPs and protocols we listen for, just picked a port at random
# because none were working
Port 380
# Use these options to restrict which interfaces/protocols sshd will bind to
#ListenAddress ::
ListenAddress  [IP Address of Apartment Complex]
Protocol 2
# HostKeys for protocol version 2
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_ed25519_key
#Privilege Separation is turned on for security
UsePrivilegeSeparation yes

# Lifetime and size of ephemeral version 1 server key
KeyRegenerationInterval 3600
ServerKeyBits 1024

# Logging
SyslogFacility AUTH
LogLevel INFO

# Authentication:
LoginGraceTime 120
PermitRootLogin no
StrictModes yes

RSAAuthentication yes
PubkeyAuthentication yes
#AuthorizedKeysFile %h/.ssh/authorized_keys

# Don't read the user's ~/.rhosts and ~/.shosts files
IgnoreRhosts yes
# For this to work you will also need host keys in /etc/ssh_known_hosts
RhostsRSAAuthentication no
# similar for protocol version 2
HostbasedAuthentication no
# Uncomment if you don't trust ~/.ssh/known_hosts for RhostsRSAAuthentication
#IgnoreUserKnownHosts yes

# To enable empty passwords, change to yes (NOT RECOMMENDED)
PermitEmptyPasswords yes

# Change to yes to enable challenge-response passwords (beware issues with
# some PAM modules and threads)
ChallengeResponseAuthentication no

# Change to no to disable tunnelled clear text passwords
PasswordAuthentication no

# Kerberos options
#KerberosAuthentication no
#KerberosGetAFSToken no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes

# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes

X11Forwarding yes
X11DisplayOffset 10
PrintMotd no
PrintLastLog yes
TCPKeepAlive yes
#UseLogin no

#MaxStartups 10:30:60
#Banner /etc/issue.net

# Allow client to pass locale environment variables
AcceptEnv LANG LC_*

Subsystem sftp /usr/lib/openssh/sftp-server

# Set this to 'yes' to enable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the ChallengeResponseAuthentication and
# PasswordAuthentication.  Depending on your PAM configuration,
# PAM authentication via ChallengeResponseAuthentication may bypass
# the setting of "PermitRootLogin without-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and ChallengeResponseAuthentication to 'no'.
UsePAM yes

输出sudo systemctl start ssh

Job for ssh.service failed because the control process exited with error code. See "systemctl status ssh.service" and "journalctl -xe" for details.

输出systemctl status ssh.service

ssh.service - OpenBSD Secure Shell server
   Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Mon 2017-06-05 22:15:30 PDT; 14s ago
   Process: 2288 ExecReload=/bin/kill -HUP $MAINPID (code=exited, status=0/SUCCESS)
   Process: 6579 ExecStart=/usr/sbin/sshd -D $SSHD_OPTS (code=exited, status=255)
 Main PID: 6579 (code=exited, status=255)

Jun 05 22:15:30 Case systemd[1]: Starting OpenBSD Secure Shell server...
Jun 05 22:15:30 Case systemd[1]: ssh.service: Main process exited, code=exited, status=255/n/a
Jun 05 22:15:30 Case systemd[1]: Failed to start OpenBSD Secure Shell server.
Jun 05 22:15:30 Case systemd[1]: ssh.service: Unit entered failed state.
Jun 05 22:15:30 Case systemd[1]: ssh.service: Failed with result 'exit-code'.

‘journalctl -xe’ 的截断输出:

Unit ssh.service has begun starting up.
Jun 05 22:15:30 Case sshd[6579]: error: Bind to port 380 on [IP Address of My Apartment Complex] failed: Cannot assign requested address.
Jun 05 22:15:30 Case sshd[6579]: fatal: Cannot bind any address.
Jun 05 22:15:30 Case systemd[1]: ssh.service: Main process exited, code=exited, status=255/n/a
Jun 05 22:15:30 Case systemd[1]: Failed to start OpenBSD Secure Shell server.
-- Subject: Unit ssh.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit ssh.service has failed.

其他详情:

我已接入无线路由器,该路由器又接入墙壁(因此 IP 地址是公寓大楼的 IP 地址)

希望这些细节足够详细!

答案1

如果您所在的公寓楼提供 wifi,那么您确实很幸运。如果是这样,您很有可能拥有 DHCP 提供的 IP 地址。这意味着每次重新启动或关闭服务器时,您都会获得新的连接租约,并且可能获得不同的 IP 地址。但是,如果这种不便对您来说不是什么大问题,您可以按照本网站上随处可见的文档配置 SSH。

SSHD 可与分配给服务器的任何 IP 地址配合使用,包括不可路由的地址和本地环回。当然,如果您想从 Internet 进行 ssh 连接,则需要有一个可从 LAN 外部访问的 IP。从他们的网站运行 speedtest 将有助于确定该 IP 是什么。

首先,输入以下内容检查您当前的 IP 地址(如果有)

ifconfig -a

设置 sshd 非常简单。根据您希望服务器访问的安全性,设置起来会稍微困难一些。在 Ubuntu 16.04 上,基本 ssh 几乎开箱即用

要测试 sshd 是否正常工作(无论网络连接如何),请输入

ssh localhost

这将允许您登录到您的服务器并验证 sshd 确实运行正确。

答案2

您可以使用反向 SSH 隧道来访问 NAT 后面的盒子。

相关内容