我正在嘗試使用 SSH 透過路由器將運行 11.10 的新筆記型電腦連結到運行 8.04 的舊筆記型電腦。
這個問題是在 ubuntuforums 上提出和回答的:
http://ubuntuforums.org/showthread.php?t=1648965
我認為在這裡得到更明確的答案會很有幫助。
注意:我需要先在嘗試連線的筆記型電腦上安裝 openssh-server,並使用 firestarter 在防火牆中開啟 SSH 連接埠。
答案1
您可以透過多種方式限制對 ssh 伺服器的存取。
IMO 最重要的是使用 ssh 金鑰並停用密碼驗證。
有關詳細信息,請參閱以下 wiki 頁面
- https://help.ubuntu.com/community/SSH/OpenSSH/Keys
- https://help.ubuntu.com/community/SSH/OpenSSH/Configuring#Disable_Password_Authentication
您可以透過多種方式限制對特定子網路的存取。我假設你的 ssh 伺服器位於子網路 192.168.0.0/16 上,IP 位址為 192.168.0.10 ,相應調整;)
路由器
一道防線是使用路由器。請務必停用 UPnP 且不允許連接埠轉送。
SSH配置
您可以在 中設定多個選項/etc/ssh/sshd_config
。一是監聽地址。如果您在子網路上設定了偵聽位址。私人IP位址無法透過網際網路路由。
ListenAddress 192.168.0.10
您也可以使用允許用戶
AllowUsers [email protected]/16
有點相關,你也可以更改端口
Port 1234
看:http://manpages.ubuntu.com/manpages/precise/man5/sshd_config.5.html
TCP 包裝器
如論壇貼文所述,您可以使用 TCP Wrapper 。 TCP 包裝器使用 2 個文件,/etc/hosts.allow
並且/etc/hosts.deny
編輯/etc/hosts.allow
並新增您的子網
sshd : 192.168.0.
編輯/etc/hosts.deny
並全部拒絕
ALL : ALL
也可以看看:http://ubuntu-tutorials.com/2007/09/02/network-security-with-tcpwrappers-hostsallow-and-hostsdeny/
防火牆
最後你可以為你的伺服器設定防火牆。您可以使用 iptables、ufw 或 gufw。
iptables
sudo iptables -I INPUT -p tcp --dport 22 -s 192.168.0.0/16 -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 22 -j REJECT
ufw
sudo ufw allow from 192.168.0.0/16 to any port 22
ufw
有圖形介面:gufw
答案2
2020 更新
由於這個問題,現在可以使用一種不太複雜的方法Match
,在OpenSSH 6.5/6.5p1 (2014):
在裡面sshd設定檔(/etc/ssh/sshd_config
在德班以及派生作業系統,例如烏班圖)
# Disable all auth by default
PasswordAuthentication no
PubkeyAuthentication no
[.. then, at the end of the file ..]
# Allow auth from local network
Match Address 192.168.1.*
PubkeyAuthentication yes
# if you want, you can even restrict to a specified user
AllowUsers stephan
提示:最好將自訂規則放在資料夾/etc/ssh/sshd_config.d
中的檔案中。通常/etc/ssh/sshd_config.d/local_network_only.conf
。這可以防止升級到新版本的 ssh-server 套件更改 sshd 設定檔時發生衝突。
man sshd_config
更多細節
答案3
ssh(安全外殼)用於安全地存取和傳輸資料(使用RSA_KEYS對)。您可以透過兩種方式使用 ssh 存取資料 1. 命令列 2. 使用檔案瀏覽器
命令列:為此,您不需要安裝任何東西。第一個任務是登入其他計算機。
ssh other_computer_username@other_computer_ip
此命令將要求輸入密碼,該密碼是另一台電腦的密碼(針對特定使用者名稱)。您剛剛登入其他電腦的 shell。認為這個終端機就像你的電腦外殼終端機。您可以使用 shell 在其他電腦上執行您可以在自己的電腦上執行的所有操作
文件瀏覽器:需要安裝openssh-server
sudo apt-get install openssh-server
要登入,請前往檔案->connectToServer