ssh带外管理

一、概述

ssh服务,一种远程管理连接工具,在CentOS7系统中默认安装并开机自启的。

SSH(Secure Shell)是一种安全通道协议,主要用来实现字符界面的远程登录,远程复制等功能。

监听tcp的22号端口。软件包名称:openssh

配置文件目录:/etc/ssh,sshd_config 服务端配置文件;ssh_config 客户端配置文件。**

客户端提供:ssh、scp、sftp命令

服务端提供:sftp服务、ssh服务

 二、 配置文件

服务端配置文件: sshd_config

[root@localhost ssh]# cat sshd_config
#       $OpenBSD: sshd_config,v 1.104 2021/07/02 05:11:21 dtucker Exp $

# This is the sshd server system-wide configuration file.  See
# sshd_config(5) for more information.

# This sshd was compiled with PATH=/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin

# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented.  Uncommented options override the
# default value.

# To modify the system-wide sshd configuration, create a  *.conf  file under
#  /etc/ssh/sshd_config.d/  which will be automatically included below
Include /etc/ssh/sshd_config.d/*.conf

# If you want to change the port on a SELinux system, you have to tell
# SELinux about this change.
# semanage port -a -t ssh_port_t -p tcp #PORTNUMBER
#
#Port 22
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::

#HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_ecdsa_key
#HostKey /etc/ssh/ssh_host_ed25519_key

# Ciphers and keying
#RekeyLimit default none

# Logging
#SyslogFacility AUTH
#LogLevel INFO

# Authentication:

#LoginGraceTime 2m
PermitRootLogin yes
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10

#PubkeyAuthentication yes

# The default is to check both .ssh/authorized_keys and .ssh/authorized_keys2
# but this is overridden so installations will only check .ssh/authorized_keys
AuthorizedKeysFile      .ssh/authorized_keys

#AuthorizedPrincipalsFile none

#AuthorizedKeysCommand none
#AuthorizedKeysCommandUser nobody

# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
#HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# HostbasedAuthentication
#IgnoreUserKnownHosts no
# Don't read the user's ~/.rhosts and ~/.shosts files
#IgnoreRhosts yes

# To disable tunneled clear text passwords, change to no here!
#PasswordAuthentication yes
#PermitEmptyPasswords no

# Change to no to disable s/key passwords
#KbdInteractiveAuthentication yes

# Kerberos options
#KerberosAuthentication no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes
#KerberosGetAFSToken no
#KerberosUseKuserok yes

# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes
#GSSAPIStrictAcceptorCheck yes
#GSSAPIKeyExchange no
#GSSAPIEnablek5users no

# Set this to 'yes' to enable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the KbdInteractiveAuthentication and
# PasswordAuthentication.  Depending on your PAM configuration,
# PAM authentication via KbdInteractiveAuthentication may bypass
# the setting of "PermitRootLogin without-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and KbdInteractiveAuthentication to 'no'.
# WARNING: 'UsePAM no' is not supported in RHEL and may cause several
# problems.
#UsePAM no

#AllowAgentForwarding yes
#AllowTcpForwarding yes
#GatewayPorts no
#X11Forwarding no
#X11DisplayOffset 10
#X11UseLocalhost yes
#PermitTTY yes
#PrintMotd yes
#PrintLastLog yes
#TCPKeepAlive yes
#PermitUserEnvironment no
#Compression delayed
#ClientAliveInterval 0
#ClientAliveCountMax 3
#UseDNS no
#PidFile /var/run/sshd.pid
#MaxStartups 10:30:100
#PermitTunnel no
#ChrootDirectory none
#VersionAddendum none

# no default banner path
#Banner none

# override default of no subsystems
Subsystem       sftp    /usr/libexec/openssh/sftp-server

# Example of overriding settings on a per-user basis
#Match User anoncvs
#       X11Forwarding no
#       AllowTcpForwarding no
#       PermitTTY no
#       ForceCommand cvs server
Port 22 #监听端口
AddressFamily any #ip地址版本
ListenAddress 0.0.0.0 #监听地址,ipv4
ListenAddress :: #监听地址,ipv6
PermitRootLogin yes #是否允许root用户登录
MaxAuthTries 6 #重新连接最大次数
MaxSessions 10 #建立不同用户的会话的最大个数
PubkeyAuthentication yes #是否启用公钥对验证登录
AuthorizedKeysFile      .ssh/authorized_keys #存储客户端公钥信息的文件
PasswordAuthentication yes #是否启用密码验证登录
PermitEmptyPasswords no #是否允许空密码登录
UsePAM yes #启用系统用户及密码进行验证登录
UseDNS no #是否启用ssh内部的解析,会影响连接速度

三、命令解析

###远程登录命令###
###语法:####
ssh [选项] [username@]ssh服务器的监听IP地址或者主机名(使用主机名时,保证客户端能够解析主机名)
####选项:######
-p port  指定连接服务器的监听端口
###远程拷贝命令####
###语法:####
##将本机的文件拷贝到远程主机##
scp  本机的文件路径  [username@]ssh服务器的监听IP地址或者主机名:/远程主机存储路径
##将远程主机的文件拷贝到本机##
scp    [username@]ssh服务器的监听IP地址或者主机名:/远程主机存储路径 本机的文件路径
###sftp服务登录命令###
sftp [选项] [username@]ssh服务器的监听IP地址或者主机名(使用主机名时,保证客户端能够解析主机名)

2、公钥验证登录

密码学基础:

概念解析
对称加密双方采用相同的秘钥,安全性较低
非对称加密双方采用不同的秘钥,安全性较高
公钥大家都可以知道的秘钥。
私钥只有自己知道的秘钥。能够证明自己的身份信息

 注意:公钥和私钥不能相互推导!!

公钥与私钥之间能够相互解密!!!

数据加密:

使用对端的公钥加密,接收端收到数据后,使用自己的私钥解密。作用是保证数据完整性。

数字签名:

私用自己的私钥加密,接收端收到数据后,使用发送端的公钥解密。作用是保证发送者的身份唯一性。
ssh客户端生成密钥对

###生成密钥对的命令###
ssh-keygen ,默认是交互式
###常用选项:####
-t : 指定秘钥算法
-N : 指定秘钥短语
-f : 指定秘钥存储路径
[root@s1 .ssh]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
###非交互生成密钥对####
[zhx1@s1 ~]$ ssh-keygen -t rsa -N '' -f ~/.ssh/id_rsa
###默认保存到当前执行该命令的用户家目录中的.ssh目录#####
[root@s1 .ssh]# ls
id_rsa  id_rsa.pub
###id_rsa: 私钥;id_rsa.pub: 公钥###
###拷贝公钥命令###
ssh-copy-id 
###ssh命令的特殊用法:远程执行ssh服务器的指令####
[root@s1 .ssh]# ssh 192.168.115.128 ip a
##注意:不能执行ssh-copy-id命令####

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值