首页 > 技术文章 > Linux开启ssh

linshengqian 2021-07-27 14:01 原文

Linux开启ssh

1.Ubuntu开启ssh服务及允许root登录

  1. 安装ssh服务器端
  • Ubuntu默认没有安装ssh的server,需要安装
apt-get install openssh-server
  • ssh客户端是默认安装的,安装包:openssh-client,apt安装
  1. 允许远程使用root账号ssh登入
  • 修改/etc/ssh/sshd_config文件,修改如下:
#PermitRootLogin prohibit-password
PermitRootLogin yes
  • 需要重启系统或者sshd服务
1.sudo /etc/init.d/ssh stop
2.sudo /etc/init.d/ssh start
3.sudo service ssh start
  • 安装ssh服务后,系统默认开启系统sshd,查看sshd状态如果不是默认启动,修改服务为enable
sudo systemctl enable ssh

2.CentOS开启SSH服务

1.安装openssh-server

yum list installed |grep openssh-server

如果有输出,证明已经安装了openssh-server,如果没有,需要安装

yum install openssh-server

2.修改sshd服务配置文件

  • 编辑sshd服务配置文件
vi /etc/ssh/sshd_config
  • 开启监听端口
Port 22
ListenAddress 0.0.0.0
ListenAddress ::
  • 允许远程登录
PermitRootLogin yes
  • 使用用户名密码作为验证连接
PasswordAuthentication yes
  • 开启sshd服务
service sshd start
  • 配置开机自启动
systemctl enable sshd

3.Kalilinux开启ssh

添加ssh开机自启动

1.查看ssh的运行状态

/etc/init.d/ssh status

2.启动ssh

/etc/init.d/ssh start

3.开机自启动配置

systemctl enable ssh.service

update-rc.d ssh enable

修改配置让ssh允许root登录

1.配置ssh配置文件

vi /etc/ssh/sshd_config

2.找到配置

原来这行:PermitRootLogin prohibit-password修改成这行:PermitRootLogin yes

3.保存退出,重启ssh服务

/etc/init.d/ssh restart

推荐阅读