安装 启动sshd服务:

1、先确认是否已安装ssh服务:

[root@localhost ~]# rpm -qa | grep openssh-server
openssh-server-5.3p1-19.fc12.i686 (这行表示已安装)
若未安装ssh服务,可输入:

#yum(或apt-get) install openssh-server
进行安装

2、修改配置文件

#vi /etc/ssh/sshd_config
#Port 22  监听的端口号,默认是22,可以自定义。
#Protocol 2  支持的协议,默认就好,不用修改
#PermitRootLogin yes 是否允许root直接登录,最好设置为no
#MMaxAuthTries 6 最大登录数,默认是6,建议设置为3,防止别人密码穷举。
修改完配置后,重启SSH服务:

[root@localhost ~]# /etc/rc.d/init.d/sshd restart
Stopping sshd: [ OK ]
Starting sshd: [ OK ]:
3、查看sshd状态:

#service sshd(或ssh) status 
4、将端口22(或者自定义的其他端口)加到防火墙的设置中,标记为Accept

#iptables -A INPUT -p tcp --dport 22 -j ACCEPT(这句很重要,不然外部连接不了。)
也可以将上述参数加入防火墙配置中:

#vi /etc/sysconfig/iptables
加入:-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
保存后重启iptables即可

注意,如果安装的系统的镜像是Fedora LiveCD,则需要使用以下命令来开启SSH服务

#Fedora LiveCD的sshd服务默认是没有开启来的,ssh需要手动开启来,开启之后需要给root添加一个密码,不然ssh登录不上的
[root@localhost ~]# systemctl enable sshd.service
ln -s '/usr/lib/systemd/system/sshd.service' '/etc/systemd/system/multi-user.target.wants/sshd.service'
[root@localhost ~]# systemctl start sshd.service
 
原文地址:https://www.cnblogs.com/sprinng/p/5235384.html