Linux_OpenSSH远程连接

简介: 目录目录SSH serverSSH服务属性SSH协议执行原理SSH连接方式ssh Commandsscp commandssftp commandsSSH在生产环境中的使用系统间备份文件rsyncSSH serverSoftware:Openssh-server Service: 1.

目录

SSH server

Software:Openssh-server
Service:
1.ssh(Security Shell)
2.sftp-server(Security File Transfer Protocol)
Configure directory:/etc/ssh

SSH服务属性

ssh(Secure Shell)协议:加密远程传输协议
ServerEnd port: 22
ClientEnd port:> 1024
配置文件:/etc/ssh/sshd_config(Server)、/etc/ssh/ssh_config(Client)
ssh Server(被连接端)发送Server公钥 —-> ssh Client(发起连接):~/.ssh/known_hosts

SSH协议执行原理

Client将拥有的公钥发送给Server并于Server的私钥进行比对。
若一致:Server用Client公钥加密一个将来传输的密码,再将密码发给Client,Clinet用自己的私钥来解密得到传输密码,Client用传输密码对数据加密。
若不一致:则拒绝访问。

SSH连接方式

1.密码验证
2.密钥验证,实现步骤:
(1)Client(连接段)生成密钥对(公钥/私钥)
ssh-keygen #Create KeyPair in /UserName/.ssh
(2)将公钥发送给Server(被连接端)
ssh-copy-id -i ~/.ssh/id_rsa.pub userName@[hostname|ip]

ssh Commands

ssh userName@[hostname|IP]   #Remote connect
ssh -X userName@[hostname|IP]  #Support GUI
ssh userName@[hostname|IP] [commands]  #[commands]:Execute following commands.

使用-X选项,需要在服务器端的/etc/ssh/ssh_config文件中设置 ForwardX11 yes 或者 X11Forwad yes,以启用 X11 Forwarding。

scp commands

scp:Security copy

scp -r [file|dir] userName@hostname:dirUrl #Copy local [file|directory] into remote host
scp -r userName@hostname:dirUrl [file|dir]  #Copy remote [file|firectory] into local host

sftp commands

sftp userName@[hostname|IP]  #Entry security ftp via protocol of ssh

连接Sftp后可以使用下面指令进行上传和下载文件
get file #dowmload the file
put file #upload the file

SSH在生产环境中的使用

一般不允许远程连接到root
在SSH Server配置:
vim /etc/ssh/sshd_config

PermitRootLogin  no

重启SSH服务

systemctl restart sshd.service

拒绝别人用密码登陆
在SSH Server配置:
vim /etc/ssh/sshd_config

PasswordAuthentication  no

重启SSH服务

systemctl restart sshd.service

系统间备份文件rsync

基于SSH协议的同步备份指令rsync
指令格式
rsync -option fileName userName@[hostname|ip]:/directory
Example:

rsync -a /etc/ 192.168.0.2:/tmp

注意
如果是/etc/ ,复制过去的是目录下面的内容
如果是/etc,复制过去的是目录和目录下面的内容
选项
-a 归档
-v 显示过程
-r 子目录
-l 同步链接文件
-p 保留权限
-t 保留时间戳
-g 保留属组
-o 保留属主

相关文章
|
1月前
|
存储 网络协议 Ubuntu
Linux环境下的SVN服务器搭建并结合内网穿透实现远程连接
Linux环境下的SVN服务器搭建并结合内网穿透实现远程连接
|
2月前
|
网络协议 关系型数据库 Linux
Linux系统中如何开启和配置OpenGauss数据库的远程连接
openGauss是一款开源关系型数据库管理系统,采用木兰宽松许可证v2发行。openGauss内核深度融合华为在数据库领域多年的经验,结合企业级场景需求,持续构建竞争力特性.
|
3月前
|
安全 Linux Shell
【Linux】文件服务OpenSSH(Secure Shell)
【Linux】文件服务OpenSSH(Secure Shell)
26 0
【Linux】文件服务OpenSSH(Secure Shell)
|
4月前
|
关系型数据库 MySQL Linux
Linux 本地 Docker Registry本地镜像仓库远程连接
Linux 本地 Docker Registry本地镜像仓库远程连接
121 0
|
6月前
|
网络协议 Ubuntu Linux
【Linux】cpolar+JuiceSSH实现手机端远程连接Linux服务器
【Linux】cpolar+JuiceSSH实现手机端远程连接Linux服务器
|
6月前
|
网络协议 关系型数据库 MySQL
【Linux环境】Centos7.x 安装MySQL,使用Navicat等远程连接工具报2003-Can‘t connect to MySQL server on(10060 Unknown err)
【Linux环境】Centos7.x 安装MySQL,使用Navicat等远程连接工具报2003-Can‘t connect to MySQL server on(10060 Unknown err)
219 0
|
6月前
|
网络协议 Ubuntu Linux
VSCode使用Remote SSH远程连接Linux服务器【远程开发】
VSCode使用Remote SSH远程连接Linux服务器【远程开发】
|
6月前
|
Linux 网络安全
55Linux - 远程连接工具(SSHSecureShellClient乱码问题解决)
55Linux - 远程连接工具(SSHSecureShellClient乱码问题解决)
88 0
|
1月前
|
网络协议 Ubuntu Linux
「远程开发」VSCode使用SSH远程linux服务器 - 公网远程连接
「远程开发」VSCode使用SSH远程linux服务器 - 公网远程连接
131 0
|
7月前
|
网络协议 关系型数据库 Linux
Linux 安装openGauss数据库 并 实现远程连接
Linux 安装openGauss数据库 并 实现远程连接
224 0