SSHを介してSambaファイルサーバーにどのように接続しますか?

SSHを介してSambaファイルサーバーにどのように接続しますか?

そのため、Debian(3.2)コンピュータに専用のSambaファイルサーバーを作成しました。私はWindowsとUnixの両方で大きな成功を収めました。ローカルネットワークからSSH経由で接続できます。

パブリックIPアドレスを介してSSH経由で接続しようとすると、接続が拒否されたというメッセージが表示されます。

リモートでSamba共有に直接SSHで接続できるようにしたいです。どうすればいいですか?先に進むべきだと聞いたのに? 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

ベストアンサー1

Scriptonaut、あなたの問題はSambaに関するものではなく、ポート転送/ NATに関連している可能性があります。 Debian を提供する SAMBA コンピュータが LAN ネットワークのルータの背後にある場合は、一部のポートからの要求を SAMBA を実行しているコンピュータに転送するように設定する必要があります。

ここに画像の説明を入力してください。

まず、ルータの発信接続がどのように機能するかを見てみましょう。両方のシステムがTCP / IPを介して通信するとき、各システム(ソースと宛先)はIP /ポート番号のペアを使用してアドレス指定されるため、接続は送信元IP /ポート番号と宛先IP /ポート番号の2つのペアによって決まります。になります。

Mozillaでタブを開き、192.168.1.2システムからGoogleにアクセスすると、送信元アドレスIP = 192.168.1.2とそのブラウザタブに送信TCPポート番号(43694など)が割り当てられているルーターにいくつかのIPパケットが送信されます。 )そして、ポート80で特定のIPを使用するGoogleシステムにそのパケットを送信するようにルーターに要求します。 80は受信http接続用の標準ポートであるため(標準TCPポートのリストについてはファイルを参照/etc/services)。ルータは独自のポート(12345など)をランダムに割り当て、そのパケットの送信元IP /ポートペアを独自のWAN IP(74.25.14.86)とポート12345に置き換えます。ポート12345でGoogleから応答を受信すると、自動的に応答を192.168.1.2、ポート43694に戻す必要があります。

今、外部コンピュータがサーバーにアクセスしようとするとどうなりますか?

外部システムからSAMBAサーバーにアクセスしようとすると、WAN IP = 74.25.14.86のポート22にIPパケットを送信します(22はSSH接続をリッスンするための標準TCPポートであるため、Linux標準のリストを見ることができます)。上記のファイルのTCPポート/etc/services)。ルータはパケットを受信します。デフォルトでは、ルーターのファイアウォールは、そのポートにバインドされた発信接続がない場合、そのポートに着信するすべての接続をブロックするように構成されています。したがって、以前のシナリオで Google にアクセスした場合、ルータはポート 12345 自体に対する Google の応答をブロックしません。 192.168.1.2 が Google への接続を開始し、Google の応答がポート 12345 に到着する必要があることを覚えているからです。ただし、ポート 22 は LAN のどの接続にもマッピングされないため、外部世界からポート 22 への接続試行をブロックします。

したがって、すべきことは、外部のすべての接続を192.168.1.2のポート22からポート22に切り替えるようにルータを設定することです。これはハードウェアルーターのネットワークインターフェイスで行うことができ、通常必要なメニューオプションを「ポート転送」または「NAT - ネットワークアドレス変換」と呼びます。

おすすめ記事