The Knowledge of Linux-.-Day04
来源:互联网 发布:安卓一键清除软件数据 编辑:程序博客网 时间:2024/04/28 15:22
1.ssh服务
ssh认识:
sshd服务:C/S,client/server
ssh:secure shell
ssh连接的过程:
实现远程连接软件:
Linux:openssh
Windows:putty,X-shell…
腾讯云:
申请云主机(1元一个月)
域名
客户端连接方式:
ssh username@server-ip //远程连接server主机,不连接图形
ssh username@server-ip -X //远程连接server主机,连接图形
ssh username@server-ip command //在远程主机执行命令返回结果scp [-r] 文件|目录 username@server-ip:/dir/
//复制本地文件或目录到远程主机,上传
scp [-r] username@server-ip:目录|文件 目录
//复制远程主机的文件或目录到本地,下载sftp username@server-ip //通过ssh协议实现交互式文件传输
实现无密码连接:
实验背景:
1)desktop:172.25.254.100 desktop100
2)server:172.25.254.200 server200
临时设置ip:
ipconfig eth0 172.25.254.100/24
设置主机名:
临时设置主机名:hostname desktop100
永久设置主机名:hostnamectl set-hostname desktop126.example.com
方法一:
desktop主机操作:
ssh-keygen //生成公钥和私钥
ls /root/.ssh/ //查看公钥和私钥文件是否存在
ssh-copy-id -i /root/.ssh/id_rsa.pub root@172.25.254.200 //通过ssh-copy-id将公钥文件传输给server主机,-i,指定传输的公钥文件
ssh root@172.25.254.200 //远程连接server主机,查看那无密码连接是否成功
server主机操作:
cat /root/.ssh/authorized_keys //查看锁文件与desktop主机的公钥文件内容是否一致
此方法过程中需要server主机的密码。
方法二:
server主机操作:
ssh-keygen //生成公钥和私钥
cd /root/.ssh/
ssh-copy-id -i id_rsa.pub root@172.25.254.200 //通过ssh-copy-id将公钥文件传输给自己,生成锁文件
scp id_rsa root@172.25.254.100:/root/.ssh/ //发送私钥给desktop主机,注意,一定要指定远程复制文件到哪个目录
desktop主机操作:
ls /root/.ssh/id_rsa //查看服务端传输私钥到客户端是否成功
ssh root@172.25.254.200 //查看无密码连接是否成功
此方法过程中desktop主机不需要知道server主机的密码,但server主机需要知道desktop主机的密码。
ssh服务的配置:
主配置文件: /etc/ssh/sshd_config
主配置文件参数:
48 PermitRootLogin yes //是否允许root用户远程登陆
78 PasswordAuthentication no //是否允许通过密码认证远程登陆
AllowUsers student //制定用户白名单
DenyUsers student //制定用户黑名单
//注意:用户白名单和用户黑名单同时存在是,黑名单先生效
刷新sshd配置:systemctl restart sshd //重新启动sshd服务
练习
已有desktop和server两台虚拟机,配置如下:
1).打包desktop主机上的/home目录,格式为YYYY_MM_DD_home.tar.gz并保存在/mnt目录;
2).无密码传输该打包文件到server主机的/home/student/目录下;
server:
ssh-keygen
ssh-copy-id -i /root/.ssh/id_rsa.pub root@172.25.254.200
scp /root/.ssh/id_rsa root@172.25.254.100:/root/.ssh
desktop:
3).desktop主机通过命令将server主机的压缩包解压到/home/student/Downloads目录下;
4).不允许以密码认证方式远程连接server主机;
5).只允许student用户通过密钥方式远程登陆;
6).为保证系统安全不允许以root用户身份连接server主机;
2.系统服务的控制 vsftpd sshd nfs
systemctl start 服务名
systemctl stop 服务名
systemctl restart 服务名 //先stop服务,再start服务
systemctl reload 服务名 //重新加载服务的配置文件,不关闭服务
systemctl status 服务名
systemctl enable 服务名 //设置该服务开机启动
systemctl disable 服务名 //设置该服务开机不启动
systemctl mask 服务名 //锁定某个服务不能启动,但可实现关闭
systemctl unmask 服务名 //解开某个服务的锁定
systemctl list-units //列出当前系统所有服务的状态
systemctl list-unit-files //列出当前系统所有服务开机状态
//static 静态,是其他服务的依赖性,自己是否启动不由自己决定
//disable
//enable
//masked
systemctl list-dependencies 服务名 //列出某个服务的依赖性
3.用户登陆审计:
w //显示当前登陆系统的用户
w -f //-f参数,显示登陆该系统的用户在哪台主机上运行
last //显示之前登录系统成功的主机及登陆时间
lastb //显示之前试图登录系统的主机及时间
- The Knowledge of Linux-.-Day04
- The Knowledge of Linux-.-Day01
- The Knowledge of Linux-.-Day03
- The Knowledge of Linux-.-Day02
- The Knowledge of Linux-.-Day05
- The Knowledge of Linux-.-Day06
- The Knowledge of Linux-.-Day07
- The Knowledge of Linux-.-Day08
- The Knowledge of Linux-.-Day12
- The Knowledge of Linux-.-Day14
- The Principle of Least Knowledge
- The packaging of wine knowledge
- The Knowledge of AHCI / AHCI 解惑
- The basic knowledge of deep learning
- The Importance of Acquiring the Methods of Gaining Knowledge Rather Than Knowledge Itself
- The advance of Java -- Genericity, Exception, IO(Day04)
- Knowledge Representation in The Many Faces of Go
- Master the game of Go without human knowledge
- CTS 问题 第四篇
- 微信小程序开发
- 在MFC中使用CListCtrl,实现每行的行高不同
- MongoDB权威指南 笔记
- <转>Spark中组件Mllib的学习26之逻辑回归-简单数据集,带预测
- The Knowledge of Linux-.-Day04
- 如何在wine下为Source Insight配置字体
- Java并发编程的艺术(五)——中断
- (HDU 5738) <计算几何 ,在n个点中找所有共线的集合> 2016 Multi-University Training Contest 2
- Java 基础知识积累 时间Date那点事
- 简单的android Listview使用例子
- java求整数的位数
- Java设计模式——工厂设计模式
- MongoDB 导出导入备份恢复数据详解及实例