Scr*_*aut 2 ssh file-server configuration samba port-forwarding
所以我在我的 Debian(3.2) 机器上做了一个专用的 Samba 文件服务器。我从 Windows 和 Unix 访问它都取得了巨大的成功。我可以在本地网络上通过 SSH 连接到它。
当我尝试通过公共 IP 地址 SSH 进入它时,它说连接被拒绝。
我希望能够远程 ssh 进入它,直接进入 Samba 共享。我该怎么做呢?我听说我可能需要转发?我需要更改 smb.conf 文件中的任何内容吗?
这是我的 sshd_config 文件:
# Package generated configuration file
# See the sshd_config(5) manpage for details
# What ports, IPs and protocols we listen for
Port 22
# Use these options to restrict which interfaces/protocols sshd will bind to
#ListenAddress ::
#ListenAddress 0.0.0.0
Protocol 2
# HostKeys for protocol version 2
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
#Privilege Separation is turned on for security
UsePrivilegeSeparation yes
# Lifetime and size of ephemeral version 1 server key
KeyRegenerationInterval 3600
ServerKeyBits 768
# Logging
SyslogFacility AUTH
LogLevel INFO
# Authentication:
LoginGraceTime 120
PermitRootLogin yes
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 no
# 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 yes
# 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
Run Code Online (Sandbox Code Playgroud)
Scriptonaut,可能您的问题与Samba无关,而与端口转发/ NAT有关。如果您的 SAMBA 在 LAN 网络中为 Debian 计算机提供服务,在路由器后面,您需要将其配置为将请求传输到其某些端口到您的 SAMBA 运行机器:
首先,我会告诉,传出连接如何与路由器一起工作。当两台机器通过 TCP/IP 通信时,每台机器(源机器和目标机器)都使用一对 IP/端口号寻址,因此连接由两对确定:源 IP/端口号和目标 IP/端口号。
当您在 Mozilla 中打开一个选项卡并在您的 192.168.1.2 机器上访问 Google 时,它会将一些 IP 数据包传输到路由器,其源地址为 IP=192.168.1.2 以及为该浏览器选项卡分配的任意传出 TCP 端口号(例如43694) 并要求路由器将该数据包传输到谷歌机器的 80 端口上具有特定 IP 的机器,因为 80 是传入 http 连接的标准端口(您可以/etc/services
在 Linux 上的文件中查看标准 TCP 端口列表)。路由器随机分配一个自己的端口(例如12345),用自己的WAN IP(74.25.14.86)和端口12345替换该数据包中的源IP/端口对,并记住,如果它在端口12345上从Google获得响应,它应该自动将该响应传输回 192.168.1.2,端口 43694。
现在,当外部机器想要访问您的服务器时会发生什么?
当您尝试从外部机器访问您的 SAMBA 服务器时,它会向您的 WAN IP=74.25.14.86,其端口 22 发送 IP 数据包(因为,22 是用于侦听 SSH 连接的标准 TCP 端口,您可以查看列表标准 TCP 端口 /etc/services
Linux 上的文件)。您的路由器接收该数据包。默认情况下,路由器上的防火墙配置为阻止到任何端口的所有传入连接,如果没有传出连接,则绑定到该端口(因此,在前一种情况下,当您访问 Google 时,路由器不会阻止从 Google 到端口的响应12345 本身,因为它记得您的 192.168.1.2 启动了与 Google 的连接,并且来自 google 的响应应该到达端口 12345)。但它会阻止尝试从外部世界发起连接到它的端口 22,因为端口 22 没有映射到任何来自 LAN 的连接。
因此,您需要做的是配置您的路由器,将所有连接到其 22 端口的连接从外部传输到 192.168.1.2 的 22 端口。这可以在硬件路由器的 Web 界面中完成,通常您需要的菜单选项称为“端口转发”或“NAT - 网络地址转换”。