如何设置SSH以使其仅限于本地网络?

我正在尝试通过我的路由器使用SSH将运行11.10的新笔记本电脑连接到运行8.04的旧笔记本电脑。

这个问题在ubuntuforums上提出并回答:

http://ubuntuforums.org/showthread.php?t=1648965

我认为在这里有一个更明确的答案会有所帮助。

注意:我需要先在我尝试连接的笔记本电脑上安装openssh-server,然后使用firestarter在防火墙中打开SSH端口。

您可以通过多种方式限制对ssh服务器的访问。

IMO最重要的是使用ssh密钥并禁用密码validation。

有关详细信息,请参阅以下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地址不能通过互联网路由。

http://compnetworking.about.com/od/workingwithipaddresses/f/privateipaddr.htm

 ListenAddress 192.168.0.10 

您也可以使用AllowUsers

 AllowUsers you@192.168.0.0/16 

有点相关,你也可以改变端口

 Port 1234 

请参阅http://manpages.ubuntu.com/manpages/precise/man5/sshd_config.5.html

TCP包装器

如论坛post所述,您可以使用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 

请不要在iptables中使用DROP,请参阅http://www.chiark.greenend.org.uk/~peterb/network/drop-vs-reject

UFW

 sudo ufw allow from 192.168.0.0/16 to any port 22 

gufw有一个图形界面

GUFW

请参阅https://help.ubuntu.com/community/UFW

https://help.ubuntu.com/community/IptablesHowTo

ssh(安全shell)用于安全地访问和传输数据(使用RSA_KEYS对)。 您可以通过两种方式使用ssh访问数据1.命令行2.使用文件浏览器

命令行:为此您不需要安装任何东西。 第一项任务是登录到其他计算机。

 ssh other_computer_username@other_computer_ip 

此命令将要求输入密码,该密码是另一台计算机的密码(对于特定的用户名)。 您刚刚登录到其他计算机的shell。 认为这个终端就像你的电脑shell终端。 您可以使用shell将所有内容用于计算机中可以执行的其他计算机

文件浏览器:您需要安装openssh-server

 sudo apt-get install openssh-server 

要登录,请转到file-> connectToServer

在此处输入图像描述