恍然 發表於 2020-3-24 18:35:00

[Linux]-Ubuntu使用

<h1 id="目标学习ubuntu系统">目标:学习ubuntu系统</h1>
<pre><code>1.安装
2.系统配置,网络配置,安全配置,软件安装
3.ansible管理ubuntu
</code></pre>
<h1 id="第1章-安装ubuntu">第1章 安装ubuntu</h1>
<h2 id="1官网地址">1.官网地址</h2>
<pre><code>https://ubuntu.com/download
</code></pre>
<h2 id="2选择版本">2.选择版本</h2>
<pre><code>Ubuntu Desktop   图形化桌面,开发喜欢用
Ubuntu Server           内核比较新,对容器支持较好
LTS                                     长期支持版
</code></pre>
<h2 id="3下载地址">3.下载地址</h2>
<pre><code>http://mirror.umd.edu/ubuntu-iso/18.04.4/ubuntu-18.04.4-live-server-amd64.iso
</code></pre>
<h1 id="第2章-安装系统">第2章 安装系统</h1>
<h2 id="1选择语言">1.选择语言</h2>
<p><img src="https://upload-images.jianshu.io/upload_images/14248468-3da667a556735dbc.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="" loading="lazy"></p>
<h2 id="2是否安装最新版">2.是否安装最新版</h2>
<p><img src="https://upload-images.jianshu.io/upload_images/14248468-259f0a5948741e44.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="" loading="lazy"></p>
<h2 id="3选择键盘">3.选择键盘</h2>
<p><img src="https://upload-images.jianshu.io/upload_images/14248468-963d1f2823df71a7.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="" loading="lazy"></p>
<h2 id="4配置网络">4.配置网络</h2>
<p><img src="https://upload-images.jianshu.io/upload_images/14248468-9716136ba3f9913e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="" loading="lazy"><br>
<img src="https://upload-images.jianshu.io/upload_images/14248468-f507a21adfbecac2.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="" loading="lazy"><br>
<img src="https://upload-images.jianshu.io/upload_images/14248468-faf9705ac1c79d8d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="" loading="lazy"></p>
<h2 id="5配置镜像地址">5.配置镜像地址</h2>
<p>清华源地址:</p>
<pre><code>https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/
</code></pre>
<p><img src="https://upload-images.jianshu.io/upload_images/14248468-10079174a994301a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="" loading="lazy"></p>
<h2 id="6配置磁盘">6.配置磁盘</h2>
<p><img src="https://upload-images.jianshu.io/upload_images/14248468-10470fde3f23760a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="" loading="lazy"><br>
<img src="https://upload-images.jianshu.io/upload_images/14248468-1e40dfe01042b43d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="" loading="lazy"><br>
<img src="https://upload-images.jianshu.io/upload_images/14248468-2c2ebb7a10f9a324.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="" loading="lazy"><br>
<img src="https://upload-images.jianshu.io/upload_images/14248468-8603a54bc31d0e77.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="" loading="lazy"></p>
<h2 id="7配置用户">7.配置用户</h2>
<p><img src="https://upload-images.jianshu.io/upload_images/14248468-87c4ae5e424ae551.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="" loading="lazy"></p>
<h2 id="8配置ssh">8.配置SSH</h2>
<p><img src="https://upload-images.jianshu.io/upload_images/14248468-cfad91656f538a4c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="" loading="lazy"></p>
<h2 id="9预装软件">9.预装软件</h2>
<p><img src="https://upload-images.jianshu.io/upload_images/14248468-29fa24655987586e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="" loading="lazy"></p>
<h2 id="10安装中">10.安装中</h2>
<p><img src="https://upload-images.jianshu.io/upload_images/14248468-dda6e050d67ad8b6.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="" loading="lazy"></p>
<h1 id="第3章-ubuntu日常使用">第3章 ubuntu日常使用</h1>
<h2 id="1用户管理">1.用户管理</h2>
<p>1.如何使用root用户</p>
<pre><code>sudo su -
</code></pre>
<p>2.普通用户如何使用超级命令</p>
<pre><code>sudo + 命令
</code></pre>
<p>3.修改root密码</p>
<pre><code>echo "root:123456"|chpasswd
</code></pre>
<p>4.何使用root登陆</p>
<pre><code>sudo vim /etc/ssh/sshd_config
PermitRootLogin yes

sudo systemctl restart sshd
</code></pre>
<p>5.免交互修改密码</p>
<pre><code>echo "root:123456"|chpasswd
</code></pre>
<p>6.创建可以登录的普通用户</p>
<pre><code>sudo useradd json -m -s /bin/bash
sudo passwd json
</code></pre>
<p>问题:<br>
使用ansible能否创建带有密码的普通用户?</p>
<h2 id="2常用配置">2.常用配置</h2>
<p>1.网卡配置<br>
参考博客:</p>
<pre><code>https://www.jianshu.com/p/7b19961ff425
</code></pre>
<p>添加第二网卡配置</p>
<pre><code>zhangya@ubuntu:~$ cat /etc/netplan/50-cloud-init.yaml         
# This file is generated from information provided by the datasource.Changes
# to it will not persist across an instance reboot.To disable cloud-init's
# network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
    ethernets:
      ens33:
            addresses:
            - 10.0.0.100/24
            gateway4: 10.0.0.2
            nameservers:
                addresses:
                - 10.0.0.2
                search:
                - 10.0.0.2
      ens38:
            addresses:
            - 172.16.1.100/24
    version: 2
</code></pre>
<p>重启网卡</p>
<pre><code>netplan apply
</code></pre>
<p>再次查看</p>
<pre><code>zhangya@ubuntu:~$ ip a
1: lo: &lt;LOOPBACK,UP,LOWER_UP&gt; mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: ens33: &lt;BROADCAST,MULTICAST,UP,LOWER_UP&gt; mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:0c:29:41:8f:71 brd ff:ff:ff:ff:ff:ff
    inet 10.0.0.100/24 brd 10.0.0.255 scope global ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe41:8f71/64 scope link
       valid_lft forever preferred_lft forever
3: ens38: &lt;BROADCAST,MULTICAST,UP,LOWER_UP&gt; mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:0c:29:41:8f:7b brd ff:ff:ff:ff:ff:ff
    inet 172.16.1.100/24 brd 172.16.1.255 scope global ens38
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe41:8f7b/64 scope link
       valid_lft forever preferred_lft forever
</code></pre>
<p>2.设置软件源</p>
<pre><code>zhangya@ubuntu:~$ cat /etc/apt/sources.list
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
</code></pre>
<p>更新仓库缓存</p>
<pre><code>sudo apt update
</code></pre>
<h2 id="3安装常用软件">3.安装常用软件</h2>
<p>0.软件包管理命令说明<br>
apt和apt-get区别</p>
<pre><code>https://blog.csdn.net/liudsl/article/details/79200134
</code></pre>
<p>apt和yum命令区别</p>
<pre><code>deb                      rpm
apt                      yum
apt update                yum makecache
apt upgrade         yum update
apt install   yum install
dpkg -i                       rpm -ivh
dpkg -r         rpm -e
</code></pre>
<h2 id="4防火墙和selinux">4.防火墙和Selinux</h2>
<p>查看防火墙规则</p>
<pre><code>sudo iptables -nL
</code></pre>
<h2 id="5ansible管理ubuntu">5.ansible管理ubuntu</h2>
<p>1.ansible使用普通账户安装软件</p>
<pre><code># cat /etc/ansible/hosts   

ansible_ssh_user=zhangya
ansible_become=true
ansible_become_method=sudo
ansible_become_password=12345678


10.0.0.100
</code></pre>
<p>安装剧本:</p>
<pre><code># cat install.yaml
- hosts: apt
tasks:
- name: Install_nginx
    apt:
      name: nginx
      state: present

- name: start nginx
    service:
      name: nginx
      state: started
      enabled: yes
</code></pre>
<p>2.创建不允许登陆的用户</p>
<pre><code># cat useradd.yaml               
- hosts: apt
tasks:
- name: 01_create_group
    group:
      name: www
      gid: 666

- name: 02_create_user
    user:
      name: www
      uid: 666
      group: www
      shell: /sbin/nologin
      create_home: no
</code></pre>
<p>3.创建带密码允许登陆的普通用户<br>
生成加密的密码:</p>
<pre><code># ansible all -i localhost, -m debug -a "msg={{ '123456' | password_hash('sha512', '123456') }}"
localhost | SUCCESS =&gt; {
    "msg": "$6$123456$37mxvJGRzjWxgD3HYl.bKq4aUXrcYV8mk0pxmqg8ARv3t9ke5ZM/NBbwTkx1FDcnLhrOX3jQc6L/NKAohhQJn/"
}
</code></pre>
<p>编写创建用户的剧本</p>
<pre><code>- hosts: apt
tasks:
- name: 01_create_group
    group:
      name: wwww
      gid: 555

- name: 02_create_user
    user:
      name: wwww
      uid: 555
      group: wwww
      shell: /bin/bash
      create_home: yes
      password: "$6$123456$37mxvJGRzjWxgD3HYl.bKq4aUXrcYV8mk0pxmqg8ARv3t9ke5ZM/NBbwTkx1FDcnLhrOX3jQc6L/NKAohhQJn/"
</code></pre>
<p>4.修改用户密码<br>
生成密码文件:</p>
<pre><code># ansible all -i localhost, -m debug -a "msg={{ '123' | password_hash('sha512', '123456') }}"
localhost | SUCCESS =&gt; {
    "msg": "$6$123456$/hZzdP1seQMNeqJU9iyZNc05gsq3FQyLjnPFPQ2C7i.Tb7WF8ogJ.V.XVlEC2slx3M8C0YkU1/L2ZDcxgTTYL0"
}
</code></pre>
<p>编写剧本:</p>
<pre><code>- hosts: apt
tasks:
- name: change_wwww_pw
    user:
      name: wwww
      password: "$6$123456$/hZzdP1seQMNeqJU9iyZNc05gsq3FQyLjnPFPQ2C7i.Tb7WF8ogJ.V.XVlEC2slx3M8C0YkU1/L2ZDcxgTTYL0"
</code></pre>
<p>5.修改root密码<br>
编写剧本</p>
<pre><code># cat user_root_passwd.yaml
- hosts: apt
tasks:
- name: change_root_passwd
    user:
      name: root
      password: "$6$123456$/hZzdP1seQMNeqJU9iyZNc05gsq3FQyLjnPFPQ2C7i.Tb7WF8ogJ.V.XVlEC2slx3M8C0YkU1/L2ZDcxgTTYL0"
</code></pre>
<h1 id="第x章-ubuntu和centos不一样的地方">第x章 ubuntu和centos不一样的地方</h1>
<p>1.默认使用普通用户登陆<br>
2.的root用户默认没有密码,也不允许ssh登陆<br>
3.普通用户想使用超级管理员命令加上sudo<br>
4.passwd命令没有--stdin选项,要想免交互,使用chpasswd<br>
5.useradd创建普通用户默认不创建家目录,默认解释器为sh<br>
6.网卡配置使用的是yaml格式<br>
7.默认没有iptables规则<br>
8.默认没有selinux</p>
<p>`</p><br><br>
来源:https://www.cnblogs.com/alaska/p/12560749.html
頁: [1]
查看完整版本: [Linux]-Ubuntu使用