ssh协议介绍 --- 创建免密通道

发布于:2023-02-11 ⋅ 阅读:(646) ⋅ 点赞:(0)

目录

一.ssh原理

一.配置文件(一部分)

引出:如何杀死黑客登录

二 . 加固

ssh搭建+配置+排错+命令

一.ssh命令

二.加密算法

三.创建免密通道(免密码)


什么是ssh?

远程控制服务器,对传输的数据进行加密,保护传输数据的安全

如何搭建ssh服务?

软件来实现某个功能。openssh

liunx里面查看openssh版本

ubunt不会默认安装openssh,自己安装openssh,在里面修改允许远程root登陆

端口:tcp22

一.ssh原理

​sshd和ssh:

d是deamon,一直在内存中运行的内存,除非人为停止的程序

一.配置文件(一部分)

#Port 22   #端口号
#AddressFamily any
#ListenAddress 0.0.0.0  ##不单独指定哪个ip地址可以访问openssh服务
#ListenAddress ::  ##ipv6,同上

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

# Ciphers and keying
#RekeyLimit default none
# Logging
#SyslogFacility AUTH
SyslogFacility AUTHPRIV
#LogLevel INFO
# Authentication:

#LoginGraceTime 2m
#PermitRootLogin yes   ##允许root用户登陆
#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   ##不设密码的用户不可以登录 

你怎么知道那些人在登陆你的liunx,在/var/log/server里面,用grep过滤即可

引出:如何杀死黑客登录

1.w :查看终端号

2.ps aux :查看进程号

3.kill -9 进程号

4.更改密码

二 . 加固

1.修改端口

2.禁用root用户

        ssh使用linux的/etc/passwd里的用户

        可以用普通用户登陆,然后给普通用户授权或者切换到root用户

        useradd guoguo

         passwd guoguo

        sudo

        su - root

为什么ssh的时候不能使用root?登录进去了可以使用root?

登录进去后就不用在使用ssh验证是否root登录。

3.升级openssh

4.密钥认证

需要配置

5.密码认证

默认开启的

经常更换密码+设置复杂的密码

ssh搭建+配置+排错+命令

一.ssh命令

1.远程登录

ssh 用户@ip号 命令 -P指定端口号

2.文件传输命令

1scp 用户@ip号:源文件 目的文件

2sftp用户@ip号

cd 远程 lcd 本机

get 下载 put 上载

二.加密算法

对称加密:用一个相同密钥加密解密

非对称加密:有公钥(publickey)和私钥(),公钥和私钥分开使用,完成数字签名(核实用户身份)和数据加密(公钥加密,私钥解密)

liunx的公钥和私钥在哪里?

/etc/ssh里面含key文件,pub结尾的是公钥。文件里面是一段字符串,是告诉加密算法加密的时候,使用的参数(盐值)。

当你用ssh连接一台机器时

The authenticity of host '192.168.0.00(192.168.0.00)' can't be established.
ECDSA key fingerprint is SHA256:AYe6omOkWiGJz/XO9SBCZcs7LNsGBGUKQCNhA8XaHf4.
ECDSA key fingerprint is MD5:9a:bc:6e:35:aa:4a:b3:71:98:ae:31:d1:fb:58:2f:42.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.0.95' (ECDSA) to the list of known hosts.
##存放连接的服务器的公钥,每行存放一台服务器公钥

进去查看-----》

[root@localhost ssh]# cd ~/.ssh/
[root@localhost .ssh]# ls
known_hosts
[root@localhost .ssh]# cat known_hosts 
192.168.0.95 ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbml.........

自己兴趣做的一个小实验:

三.创建免密通道(免密码)

准备工作:准备两台机器(都用权限最大的root用户)

a:192.168.0.1

b:192.168.0.2

实验步骤:

1.创建密钥对(a做客户机,c做服务机)

[root@localhost .ssh]# ssh-keygen -t rsa
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:      ##这里因为建立免密通道,所以敲回车就可以了
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:FXkSMtmr3VkA1A4NdtaZTE2Ml74/oGRgcI47PoRHmps root@localhost.localdomain
The key's randomart image is:
+---[RSA 2048]----+
|        o+BBo+.Bo|
|       ..==+= *.+|
|        = .* ... |
|       o =. . .. |
|      = So.. o  .|
|     + =. .oo. . |
|      * . o . . .|
|     E o   .   ..|
|        .       .|
+----[SHA256]-----+
[root@localhost .ssh]# ls
id_rsa  id_rsa.pub  known_hosts

2.上传公钥到主机b

ssh-copy-id -i id_rsa.pub root@192.168.0.93 ##这里可以用scp,但这个命令更加方便

3.连接到主机b,所有有关ssh的服务就不需要密码了,两台机器已经建立了信任关系

目前只是单向的免密通道

 如图所示,用ssh登陆已经不用密码验证了

本文含有隐藏内容,请 开通VIP 后查看

网站公告

今日签到

点亮在社区的每一天
去签到