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-serverService:
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 copyscp -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 保留属主
相关文章推荐
- linux 下eclipse 及c/c++开发环境的搭建:
- linux下c/c++实例之七递归扫描目录下的文件
- Linux下用makepasswd和passwordmaker生成密码
- Linux通信的几种方法
- Cannot open the disk 'F:\centos64-final\CentOS 64-bit\CentOS 64-bit.vmdk' orone of the snapshot disk
- linux中likely()和unlikely()宏
- Linux 学习笔记 (四)Ubuntu14.04 解决上网问题安装无线网卡驱动
- Linux 学习笔记 (四)Ubuntu14.04 解决上网问题安装无线网卡驱动
- linux内核input子系统解析
- 根据红帽RHEL7官方文档对centos7进行技术剖析(一)
- Linux workqueue工作原理
- Linux系统下使用pwgen生成密码的使用教程
- (一)安装Linux时的磁盘划分
- Centos 查看系统信息
- 修改Linux安装软件镜像源为阿里云
- linux下c/c++实例之六时间测试和定时器
- 如何在CentOS 7.x中安装OpenERP(Odoo)
- svn命令在linux下的使用
- 如何在CentOS 7.x中安装OpenERP(Odoo)
- 如何在CentOS 7.x中安装OpenERP(Odoo)