Debian Linux安装OpenSSH SSHD服务器
时间:2020-01-09 14:16:13 来源:igfitidea点击:
如何在Debian GNU/Linux操作系统下安装OpenSSH sshd服务器?
您需要使用apt-get或aptitude命令在Debian Linux下安装OpenSSH服务器。
打开终端并输入以下命令以超级用户身份更新软件包数据库:
# apt-get update
在Debian Linux下安装OpenSSH服务器
执行以下命令:
# apt-get install openssh-server
输出示例:
Reading package lists... Done Building dependency tree Reading state information... Done Suggested packages: ssh-askpass rssh molly-guard ufw The following NEW packages will be installed: openssh-server 0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded. Need to get 318 kB of archives. After this operation, 717 kB of additional disk space will be used. Get:1 http://mirror.anl.gov/debian/ squeeze/main openssh-server amd64 1:5.5p1-6+squeeze1 [318 kB] Fetched 318 kB in 3s (89.0 kB/s) Preconfiguring packages ... Selecting previously deselected package openssh-server. (Reading database ... 153448 files and directories currently installed.) Unpacking openssh-server (from .../openssh-server_1%3a5.5p1-6+squeeze1_amd64.deb) ... Processing triggers for man-db ... Setting up openssh-server (1:5.5p1-6+squeeze1) ... Creating SSH2 RSA key; this may take some time ... Creating SSH2 DSA key; this may take some time ... Restarting OpenBSD Secure Shell server: sshd.
默认情况下,openssh将在TCP端口22上运行。
您可以使用以下命令进行验证:
# netstat -tulpn | grep :22
输出示例:
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 3946/sshd tcp6 0 0 :::22 :::* LISTEN 3946/sshd
您可以连接到Openssh服务器,执行:
$ ssh user@localhost $ ssh user@sever-ip-here
如何在Debian Linux下启动/停止/重启OpenSSH服务器?
以超级用户身份执行以下命令:
# service ssh stop # service ssh start # service ssh restart # service ssh status
或者
# /etc/init.d/ssh stop # /etc/init.d/ssh start # /etc/init.d/ssh restart # /etc/init.d/ssh status
如何在防火墙级别打开端口22?
编辑防火墙脚本,并追加以下规则以限制对192.168.1.0/24的访问题描述:
/sbin/iptables -A INPUT -s 192.168.1.0/24 -m state --state NEW -p tcp --dport 22 -j ACCEPT
保存并关闭文件。
或者,您可以按如下所示执行命令并将其保存到防火墙配置文件中:
# /sbin/iptables -A INPUT -s 192.168.1.0/24 -m state --state NEW -p tcp --dport 22 -j ACCEPT # iptables-save > /path/to/your.firewall.conf
如何在Debian Linux下配置和保护OpenSSH服务器?
您需要使用文本编辑器(例如vi)编辑/etc/ssh/sshd_config文件,运行:
# vi /etc/ssh/sshd_config