其他分享
首页 > 其他分享> > SSH远程访问

SSH远程访问

作者:互联网

目录

SSH服务及配置文件

应用层 TCP 22端口
SSH(Secure Shell)时一种安全通道协议,主要用来实现字符界面的远程登录,复制等功能
SSH(Secure Shell)协议对通信双方的数据传输进行了加密处理,安全性更好
服务名称:sshd
服务端主程序目录:/usr/sbin/sshd
服务端配置文件目录:/etc/ssh/sshd_config
客户端配置文件目录:/etc/ssh/ssh_config
ssh -t 检查是否有出错

/etc/ssh/sshd_config 配置信息

白名单AllowUsers:允许指定用户登录,拒绝所有人 —安全性场合高
黑名单DenyUsers:拒绝指定用户,允许所有人 —安全性低的场合
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

SSH远程登陆

通过ssh命令可以远程登录sshd服务,为用户提供一个安全的Shell环境,以便对服务器进行管理和维护。使用时应指定登录用户、目标主机地址作为参数。
端口号不一样 可以在后面加 -p 端口号

[root@localhost ~]# ssh root@192.168.88.136
The authenticity of host '192.168.88.136 (192.168.88.136)' can't be established.
ECDSA key fingerprint is SHA256:tqIGsl6+5/Lyxbp9PqAOMu+fxlRdynwrW4QwethKrzE.
ECDSA key fingerprint is MD5:16:46:a1:99:64:8c:91:6a:1a:48:9f:2d:3e:98:54:df.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.88.136' (ECDSA) to the list of known hosts.
Last login: Tue May 25 11:56:32 2021
[root@localhost ~]# 

登陆方式验证

对于服务器的远程管理,除了用户账县的定人城I从登录哈证的方式也非常重要。sshd 服务支持两种验证方式——密码哈证宓钼对哈证,可以设置只使用其中一种方式,也可以两种方式都启用。

密码验证

以服务器中本地系统用户的登录名称、密码进行验证。这种方式使用最为简便,但从客户机角度来看,正在连接的服务器有可能被假冒:从服务器角度来看,当遭遇密码穷举(暴力破解)攻击时防御能力比较弱。

密钥对验证

要求提供相匹配的密钥信息才能通过验证。通常先在客户机中创建一对密钥文件(公钥、私钥),然后将公钥文件放到服务器中的指定位置。远程登录时系统将使用公钥、私钥进行加密/解密关联验证,大大增强了远程管理的安全性。
1.公钥和私钥是成对生成的,这两个密钥互不相同,可以互相加密和解密。
2.不能根据一个密钥来推算出另一个密钥。
3.公钥对外公开,私钥只有私钥的持有人才知道。
公钥与私钥要配对使用,如果用公钥对数据进行加密,只有用相对应的私钥才能解密;如果用私钥对数据进行加密,那么只有用对应的公钥才能解密。
当密码验证、密钥对验证都启用时,服务器将优先使用密钥对验证。对于安全性要求较高的服务器,建议将密码验证方式禁用,只允许启用密钥对验证方式;若没有特殊要求,则两种方式都可启用。

[root@localhost ~]# ssh-keygen  -t RSA  生成密钥(ECDSA默认为RSA)
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Created directory '/root/.ssh'.
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:0YN6ctxFgc0k8eSBWfzGBb+wLDErLf/fitWHhbwoZRk root@localhost.localdomain
The key's randomart image is:
+---[RSA 2048]----+
|          o@B... |
|         o+*+. ..|
|        o ooE+ ..|
|       o o.o=+*..|
|      o So.+++o..|
|       +  +o.. = |
|          ... + o|
|           ..o  o|
|            ..oo.|
+----[SHA256]-----+
[root@localhost ~]# ssh-copy-id root@192.168.88.133   将公钥给服务端
The authenticity of host '192.168.88.133 (192.168.88.133)' can't be established.
ECDSA key fingerprint is SHA256:tqIGsl6+5/Lyxbp9PqAOMu+fxlRdynwrW4QwethKrzE.
ECDSA key fingerprint is MD5:16:46:a1:99:64:8c:91:6a:1a:48:9f:2d:3e:98:54:df.
Are you sure you want to continue connecting (yes/no)? y
Please type 'yes' or 'no': 
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
The authenticity of host '192.168.88.133 (192.168.88.133)' can't be established.
ECDSA key fingerprint is SHA256:tqIGsl6+5/Lyxbp9PqAOMu+fxlRdynwrW4QwethKrzE.
ECDSA key fingerprint is MD5:16:46:a1:99:64:8c:91:6a:1a:48:9f:2d:3e:98:54:df.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@192.168.88.133's password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'root@192.168.88.133'"
and check to make sure that only the key(s) you wanted were added.

[root@localhost ~]# ssh root@192.168.88.135   服务端通过公钥和客户端建立连接
The authenticity of host '192.168.88.135 (192.168.88.135)' can't be established.
ECDSA key fingerprint is SHA256:+F5OKh7ig57Px2GYw+VdWeXZ1iFFxs5SU3YMamz87tY.
ECDSA key fingerprint is MD5:f5:29:7e:00:02:fd:2e:54:b0:c9:50:ec:c3:e4:3f:11.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.88.135' (ECDSA) to the list of known hosts.
root@192.168.88.135's password: 
Last login: Tue May 25 19:56:08 2021

scp远程复制

通过scp命令可以利用SSH安全连接与远积士机相百复制文件。使用scp命令时,除了必须指定复制源、目标之外,还应指定目标主机地址、登录田户,执行后提示验证口令即可。例如,以下操作分别演示了下行、上行复制的操作过程,将远程主机中的/etc/passwd文件复制到本机,并将本机的/etc/vsftpd目录


[root@localhost ~]# scp -rp root@192.168.88.135:a  /opt
root@192.168.88.135's password: 
[root@localhost ~]# ls /opt/
a  rh

sftp安全FTP

通过sftp命令可以利用SSH安全连接与远程主机上传、下载文件,采用了与FTP类似的登录过程和交互式环境,便于目录资源管理。例如,以下操作依次演示了sftp登录、浏览、文件上传等过程。

[root@localhost ~]# sftp 192.168.30.3       //建立连接
root@192.168.30.3's password:          //输入密码 
Connected to 192.168.30.3.   

sftp> ls      //查看192.168.30.3目录下文件
anaconda-ks.cfg        initial-setup-ks.cfg   下载                 公共                 图片                 
文档                 桌面                 模板                 视频                 音乐                 
sftp> lls       //查看本机目录下文件
anaconda-ks.cfg  initial-setup-ks.cfg  pwd3.txt  公共  模板  视频  图片  文档  下载  音乐  桌面
sftp> get /etc/passwd     //下载文件
Fetching /etc/passwd to passwd
/etc/passwd                                                                       100% 2310     1.8MB/s   00:00    
sftp> put /root/passwd    //上传文件
Uploading /root/passwd to /root/passwd
/root/passwd                                                                      100% 2310     2.5MB/s   00:00   

标签:验证,192.168,ECDSA,访问,ssh,key,root,远程,SSH
来源: https://blog.csdn.net/DAHA2/article/details/117255059