您的位置:首页 > 运维架构 > Linux

Linux_OpenSSH远程连接

2015-11-09 10:51 585 查看

目录

目录

SSH server
SSH服务属性

SSH协议执行原理

SSH连接方式

ssh Commands

scp commands

sftp commands

SSH在生产环境中的使用

系统间备份文件rsync

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 保留属主
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: