码迷,mamicode.com
首页 > 系统相关 > 详细

linux的ssh相关指令

时间:2018-09-20 22:17:37      阅读:273      评论:0      收藏:0      [点我收藏+]

标签:inux   root   内容   theme   系统   nbsp   cat   需要   data   

1.安装ssh

apt-get install openssh-server

2.备份ssh的配置文件

sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak

3.新装的ssh需要修改配置文件

vi /etc/ssh/sshd_config

  配置文件修改这几处地方  

Port = 22 # 默认是22端口,如果和windows端口冲突或你想换成其他的否则不用动
#ListenAddress 0.0.0.0 # 如果需要指定监听的IP则去除最左侧的井号,并配置对应IP,默认即监听PC所有IP
PermitRootLogin no # 如果你需要用 root 直接登录系统则此处改为 yes
PasswordAuthentication no # 将 no 改为 yes 表示使用帐号密码方式登录

4.启动ssh

service ssh start            # * Starting OpenBSD Secure Shell server sshd
# 或者
/etc/init.d/ssh start # * Starting OpenBSD Secure Shell server sshd

  如果提示错误信息中包含could not load host key 则需要重新生成 key

sudo rm /etc/ssh/ssh*key # 先移除旧的key
dpkg-reconfigure openssh-server

  生成之后需要重启SSH服务使新的密钥生效:     

service ssh restart          # * Restarting OpenBSD Secure Shell server sshd
# 或者
/etc/init.d/ssh restart       # * Restarting OpenBSD Secure Shell server sshd

  启动、停止和重启ssh的命令如下

/etc/init.d/ssh start         # * Starting OpenBSD Secure Shell server sshd
/etc/init.d/ssh stop          # * Stopping OpenBSD Secure Shell server sshd
/etc/init.d/ssh restart       # * Restarting OpenBSD Secure Shell server sshd

5.查看服务状态

service ssh status
# * sshd is running  显示此内容则表示启动正常

6.查看ssh是否启动

ps -e | grep ssh

  如果ssh已经启动则会提示

  469 ?        00:00:00 sshd

7.设置ssh开机自启动

sudo systemctl enable ssh    #说明:sudo是提升权限,systemctl是服务管理器,enable是systemctl的参数,表示启用开机自动运行,ssh是要设置的服务名称。

  注:如果要设置开机禁止启动则

sudo systemctl disable ssh   #说明:sudo是提升权限,systemctl是服务管理器,disable是systemctl的参数,表示禁止开机运行,ssh是要设置的服务名称。

  

  

 

linux的ssh相关指令

标签:inux   root   内容   theme   系统   nbsp   cat   需要   data   

原文地址:https://www.cnblogs.com/caixiaohua/p/9683591.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!