Linux-SSH远程管理

前言

  • 大多数企业服务器是通过远程登录的方式来进行管理的
  • 当需要从一个工作站管理数以百计的服务器主机时,远程维护的方式将更占优势

一、SSH远程管理

1.1 SSH协议

  • 为客户机提供安全的shell环境,用于远程管理
  • 默认端口:TCP 22

1.2 OpenSSH服务

  • 服务名称:sshd

  • 服务端主程序:/usr/sbin/sshd

  • 服务端配置文件:/etc/ssh/sshd_config

    ssh_config:针对客户端

    sshd_config:针对服务端

访问形式端口号
SSH:密文访问默认端口 TCP:22,一般广域网
Telnet:明文形式的访问 TCP 23,一般局域网
远程桌面 3389,图形化界面
   
名称作用
mstsc(cmd命令提示符输入mstsc,根据提示操作) 微软中远程桌面的形式,只可一个用户一个终端登录,可复制文件,微软对微软
VNC 跨终端远程软件
teanviewer 远程访问软件

1.3 服务监听选项

  • 服务监听选项

             端口号,协议版本,监听IP地址

             禁用反向解析

[root@localhost ~]# vim /etc/ssh/sshd_config
...
#Port 22		'端口号可以修改'
#AddressFamily any
#ListenAddress 0.0.0.0	'监听地址可修改'
#ListenAddress ::

1.4 用户登录控制

  • 禁止root用户,空密码用户
  • 登录时间,重试次数
  • AllowUsers(白名单,仅允许,只有这些可以登录)
  • DenyUsers(黑名单,仅拒绝,只有这些不行)
  • AllowUsers不可与DenyUsers同时使用
[root@localhost ~]# vim /etc/ssh/sshd_config
LoginGraceTime 2m
PermitRootLogin yes
StrictModes yes
MaxAuthTries 6
MaxSessions 10
...
AllowUsers lisi admin@192.168.20.30    '仅允许lisi用户在终端192.168.20.30登录'

1.5 登录验证方式

  • 密码验证:核对用户名,密码是否匹配

    密钥对验证:核对客户的私钥,服务端公钥是否匹配

  • 密钥对:包含公钥,私钥

    公钥:服务器使用

    私钥:客户保留

    非对称秘钥:RSA

    对称秘钥:3DES,AES

[root@localhost ~]# vim /etc/ssh/sshd_config
PasswordAuthentication yes	'是否使用密码'
PermitEmptyPasswords no	         '禁止空密码'
PasswordAuthentication yes	'是否需要密码验证'
    
PubkeyAuthentication yes	'开启公钥验证'

AuthorizedKeysFile      .ssh/authorized_keys  '指定公钥库位置'

  

二、使用SSH客户端程序

2.1 SSH客户端程序命令

  • ssh命令–远程安全登录
命令基本格式
ssh user@host

    例如
[root@55~]# ssh root@192.168.197.142		'以root用户登录对方主机'
The authenticity of host '192.168.197.142 (192.168.197.142)' can't be established.
ECDSA key fingerprint is SHA256:Eer6tAEbaZylH0v8F1nr+ShthK1rjZl3eRi7UTw4RX4.
ECDSA key fingerprint is MD5:de:d7:cf:23:bd:8d:a1:02:ff:23:a2:4b:94:fe:e7:02.
Are you sure you want to continue connecting (yes/no)? yes	'输入yes'
Warning: Permanently added '192.168.197.142' (ECDSA) to the list of known hosts.
root@192.168.197.142's password: 	输入对方密码'
Last login: Thu Nov 21 17:37:59 2019 from 192.168.197.1
[root@66~]# 
    还有会开启 /etc/pam.d/su服务模块的情况,需要注意权限
  • scp命令–远程安全复制
命令基本格式
格式一:scp user@host:file 1 file 2
格式二:scp file 1 user@host:file 2

[root@55 ~]# scp /etc/hosts root@192.168.197.142:/etc/hosts	'将本机文件/etc/hosts以root权限复制到192.168.197.142中'
root@192.168.197.142's password: 
hosts    
    或者
[root@55 ~]# scp root@192.168.197.142:/etc/hosts /etc/hosts1
root@192.168.197.142's password: 
hosts  
  • sftp命令–安全FTP上下载
命令基本格式
sftp user@host
    get:下载
    put:上传

例如
[root@55 ~]# sftp root@192.168.197.142
root@192.168.197.142's password: 
Connected to 192.168.197.142.
sftp> ls

  

道阻且长,行则将至!加油! --不是冷漠
原文地址:https://www.cnblogs.com/bushilengmo/p/13859010.html