码迷,mamicode.com
首页 > 其他好文 > 详细

远程访问,文件的压缩,ip地址的设置(9,11,12unit)

时间:2016-10-14 00:57:38      阅读:280      评论:0      收藏:0      [点我收藏+]

标签:linux


第九单元——远程访问

1.什么是openssh

是一个提供远程访问控制的软件

2.如何实现远程访问

ssh 远程主机用户@远程主机ip地址

ssh root@172.25.254.1

The authenticity of host ‘172.25.254.1 (172.25.254.1)‘ can‘t be established.

ECDSA key fingerprint is 55:dd:43:ce:bf:94:dd:91:49:e7:97:29:63:3d:02:02.

Are you sure you want to continue connecting (yes/no)? yes /*建立安全传输key

root@172.25.254.1‘s password: /*密码输入没有回显

Last failed login: Sun Oct 11 16:56:29 CST 2015 from 172.25.254.206 on ssh:notty

There was 1 failed login attempt since the last successful login.

Last login: Sun Oct 11 16:55:46 2015 from 172.25.254.206

[root@foundation1 ~]# /*登陆成功

ctrl +d |logout ###退出

[root@foundation1 ~]# logout

Connection to 172.25.254.1 closed.

[root@localhost ~]# vim /etc/motd /*设定登陆显示字符

3.ssh的key认证

#######生成key###########

[test@foundation0 ~]$ ssh-keygen /*生成公钥和私钥的工具

Generating public/private rsa key pair.(绿色字体为自动生成过程)

Enter file in which to save the key (/home/test/.ssh/id_rsa):『enter』 ###指定加密字符保存文件,使用默认

Created directory ‘/home/test/.ssh‘.

Enter passphrase (empty for no passphrase): ###密码,必须大于4位

Enter same passphrase again:

Your identification has been saved in /home/test/.ssh/id_rsa.

Your public key has been saved in /home/test/.ssh/id_rsa.pub.

The key fingerprint is: ###确认密码

a5:4f:02:51:68:59:f4:e8:e3:c5:91:1f:6f:86:99:06 test@foundation0.ilt.example.com

The key‘s randomart image is:

+--[ RSA 2048]----+

| .*+ |

| +. o . |

| .. . E . |

| o + + * |

| S + * + |

| . * . o |

| . . |

| |

| |

+-----------------+

[test@foundation0 .ssh]$ pwd

/home/test/.ssh ###生成密钥存放位置

[test@foundation0 .ssh]$ ls

id_rsa id_rsa.pub ####id_rsa位私钥,id_rsa.pub位公钥

#####################使用key加密目标主机的目标用户############

[test@foundation0 ~]$ ssh-copy-id -i /home/test/.ssh/id_rsa.pub westos@172.25.254.100

The authenticity of host ‘172.25.254.100 (172.25.254.100)‘ can‘t be established.

ECDSA key fingerprint is eb:24:0e:07:96:26:b1:04:c2:37:0c:78:2d:bc:b0:08.

Are you sure you want to continue connecting (yes/no)? yes

/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already

installed

/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the

new keys

westos@172.25.254.100‘s password:

Number of key(s) added: 1

Now try logging into the machine, with: "ssh ‘westos@172.25.254.100‘"

and check to make sure that only the key(s) you wanted were added.

ssh-copy-id #### 上传key的工具

-i ####指定使用的公钥

/home/test/.ssh/id_rsa.pub /*使用公钥的名称

westos              /*被管理的目标用户

172.25.254.100         /*被管理用户所在主机的ip

authorized_keys        /*此文件在目标用户加目录的.ssh中,这个文件就是目标用户被加密的标                    识,文件内容位公钥内容。

4.sshd服务的简单配置

vim /etc/ssh/sshd_config      /*sshd服务的配置文件

48 PermitRootLogin yes|no     /*是否允许root用户通过sshd的认证

78 PasswordAuthentication yes|no /*开启或关闭用户密码认证

AllowUsers student westos     /*用户白名单,只允许在名单中出现的用户使用sshd服务(当白名单为空时,所有人不得访问)

DenyUsers westos            /*用户黑名单

systemctl restart sshd        /*从新加载配置(每次修改sshd文件后,需要重新启动



第十二单元-----文件的压缩和远程传递

1.文件压缩:即文档归档,就是把多个文件变成一个归档文件.

tar     c     /*创建

      f     /*指定归档文件的名称

     t     /*显示归档文件的内容

     r     /*向归档文件中添加内容

     --get   /*取出归档文件中的单个文件

     --delete  /*删除归档文件中的单个文件

     x     /*取出归档文件中的所有内容

     -C    /*指定解档目录

     -z     /*gz格式压缩

     -j     /*z2格式压缩

     -J     /*xz格式压缩

2.压缩和解压格式

gz

gzip file.tar.            /*压缩成gz格式

gungzip file.tar.gz         /*解压gz格式的压缩包

du-sh file.tar.gz            /*参看文件大小

tar zcf file.tar.gz /file     /*把文档归档为tar并压缩为gz

tar zxf file.tar.gz        /*解压解档gz格式压缩包

bz2

bzip2 file.tar           /*压缩成bz2格式

bunzip2 file.tar.bz2         /*解压bz2格式的压缩包

tar jcf file.tar.bz2 /file     /*把文档归档为tar并压缩成bz2

tar jxf file.tar.bz2        /*解压并解档bz2格式压缩bz2

zip

zip -r file.tar.zip file.tar   /*压缩成zip格式

unzip file.tar.zip         /*解压zip格式的压缩包

xz

xz file.tar             /*压缩成xz格式

unxz file.tar.xz           /*解压xz格式的压缩包

tar Jcf file.tar.xz /file      /*把文件归档为tar并压缩成zx

tar Jxf file.tar.xz          /*解压并归档xz格式压缩包

3.系统中文件远程传输

scp /*远程复制

scp file user@ip:/directory /*上传文件

scp -r dir user@ip:/directory /*长传目录

scp user@ip:/filename /direcotry /*下载文件

scp -r user@ip:/directory /direcotry /*下载目录

rsync /*远程同步

rsync file|direcotry user@ip:/directory

rsync user@ip:/directory /directory

rsync [参数] file username@ip:/dir

    -r     /*同步目录

    -l     /*不忽略链接

    -p     /*不忽略文件权限

    -t     /*不忽略文件时间戳

    -g     /*不忽略文件所有组

    -o     /*不忽略文件所有人

    -d     /*不忽略块设备

第十一单元ip地址的设置

1.ip基础知识

  1. ipv4:二进制32位

  2. 172.25.0.10/255.255.255.0

    ipaddr 172.25.0.10

    子网掩码:255.255.255.0

    子网掩码255位对应的ip位的网络位

    子网掩码0对应的ip的主机位

2.配置ip

  1. 图形界面:nm-connection-editor

  2. 文本界面:nmtui

  3. 命令配置ip

    ifconfig 网卡 ip netmask 临时设定

    nmcli connection add type ethernet con-name westos ifname eth0 autoconnect yes/*添加动态网

    nmcli connection add type ethernet con-name westos ifname eth0 ip4 ip/24/*静态网

    nmcli connection delete westos

    nmcli connection show

    nmcli connection down westos

    nmcli connection up westos

    nmcli connection modify"westos "ipv4.addresses newip/24

    nmcli connection modify"westos eth0"ipv4.method <auto|manual>

    nmcli device connect eth0

    nmcli device disconnect eth0

    nmcli device  show

    nmcli device  status 

  4. 网络配置文件

    /etc/sysconfig/network-scripts/   /*网络配置目录

  5. 文件的方式编辑ip()

    1)###动态网络配置###

    vim ifcfg-xxx      /*网络配置文件格式

    DEVICE=eth0       /*指定文件管理的设备名称

    BOOTPROTO=dhcp     /*dhcp动态获取,none和static都表示静态网络

    ONBOOT=yes        /*开机自动激活设备

    NAME=hello        /*指定网络链接的名字为hello

    2)###静态网络配置###(可以设置多个ip地址

    vim ifcfg-xxx          /*网络配置文件格式

    DEVICE=eth0            /*指定文件管理的设备名称

    BOOTPROTO=static|none dhcp  /*动态获取,none和static都表示静态网络

    ONBOOT=yes             /*开机自动激活设备

    NAME=hello             /*指定链接名字

    IPADDR=172.25.254.100      /*设定ip为172.25.254.100

    NETMASK=255.255.255.0      /*子网掩码为255.255.255.0

    PREFIX=24              /*子网掩码为255.255.255.0

技术分享

技术分享


远程访问,文件的压缩,ip地址的设置(9,11,12unit)

标签:linux

原文地址:http://12126441.blog.51cto.com/12116441/1861533

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!