美文网首页
Linux系统基础001

Linux系统基础001

作者: 平知 | 来源:发表于2019-08-10 21:05 被阅读0次
    章节号 内容            
    1 导言
    1-1 应用
    1-1-1 方法


    第1章节 导言

      Ubuntu的版本命名解读及安装时的选择:

      如:Ubuntu 18.04
      1、18指代年份,为主版本号。(一般双数为长期支持版本,单数为短期支持版本)
      2、04指代月份,为副版本号。(一般为04或者10,一般4月版为稳定版本,10月版本为测试版本)
      !建议:安装双数.04版本最好。!


    • 1-1 导言-Shell

      常用的shell有:bsh,bash,csh,ksh等等。在/etc/shells中可以查看(系统:Ubuntu)。

    root@li-System-Product-Name:/# cat /etc/shells
    # /etc/shells: valid login shells
    /bin/sh
    /bin/bash
    /bin/rbash
    /bin/dash
    

      图形界面下的终端(terminal)都是虚拟终端,用来和用户交互。在终端中输入命令,大致计算机处理过程如下:
      1、终端接收用户输入(如ls)
      2、终端将用户输入传递给shell
      3、shell查找系统环境变量,寻找命令所在路径
      4、找到命令后,shell开始调用程序,调用结束后,shell接收程序输出再返回给终端

    环境变量PATH的内容:

    li@li-ThinkPad-T420s:~$ echo $PATH
    /home/li/.local/bin:
    /usr/local/sbin:
    /usr/local/bin:
    /usr/sbin:
    /usr/bin:
    /sbin:
    /bin:
    /usr/games:
    /usr/local/games:
    /snap/bin
    
      1-1-1. 导言-Shell-使用命令的一些技巧

      1、输入命令时遇到较长的文件或者文件夹名,可以使用tab自动补全。
      2、history命令查看输入历史记录。Ctrl+P或者可向上遍历命令。Ctrl+N或者可向下遍历命令。
      3、Ctrl+B或者,向后移动光标。Ctrl+F或者向前移动光标。
      4、光标在命令输入时处于命令字符串的中间位置时候,使用Ctrl+D或者Delete删除光标盖住的(光标后面)字符。
      5、Ctrl+H或者Backspace删除光标前面的字符。
      6、Ctrl+U或者 一次性删除光标面全部字符串。
      7、Ctrl+K或者 一次性删除光标面全部字符串。
      8、Ctrl+A光标移动至字符串头部。
      9、Ctrl+E光标移动至字符串尾部。



    • 1-2 导言-用户管理

      1-2-1. 导言-用户管理-用户的分类及介绍

      用户分为:1、超级用户(root); 2、系统用户;3、普通用户。
      用户管理文件:/etc/passwd

    root@li-System-Product-Name:/# cat /etc/passwd
    root:x:0:0:root:/root:/bin/bash
    daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
    bin:x:2:2:bin:/bin:/usr/sbin/nologin
    sys:x:3:3:sys:/dev:/usr/sbin/nologin
    sync:x:4:65534:sync:/bin:/bin/sync
    games:x:5:60:games:/usr/games:/usr/sbin/nologin
    man:x:6:12:man:/var/cache/man:/usr/sbin/nologin
    lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin
    mail:x:8:8:mail:/var/mail:/usr/sbin/nologin
    news:x:9:9:news:/var/spool/news:/usr/sbin/nologin
    uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin
    proxy:x:13:13:proxy:/bin:/usr/sbin/nologin
    www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin
    backup:x:34:34:backup:/var/backups:/usr/sbin/nologin
    list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin
    irc:x:39:39:ircd:/var/run/ircd:/usr/sbin/nologin
    gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin
    nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin
    systemd-network:x:100:102:systemd Network Management,,,:/run/systemd/netif:/usr/sbin/nologin
    systemd-resolve:x:101:103:systemd Resolver,,,:/run/systemd/resolve:/usr/sbin/nologin
    syslog:x:102:106::/home/syslog:/usr/sbin/nologin
    messagebus:x:103:107::/nonexistent:/usr/sbin/nologin
    _apt:x:104:65534::/nonexistent:/usr/sbin/nologin
    uuidd:x:105:111::/run/uuidd:/usr/sbin/nologin
    avahi-autoipd:x:106:112:Avahi autoip daemon,,,:/var/lib/avahi-autoipd:/usr/sbin/nologin
    usbmux:x:107:46:usbmux daemon,,,:/var/lib/usbmux:/usr/sbin/nologin
    dnsmasq:x:108:65534:dnsmasq,,,:/var/lib/misc:/usr/sbin/nologin
    rtkit:x:109:114:RealtimeKit,,,:/proc:/usr/sbin/nologin
    cups-pk-helper:x:110:116:user for cups-pk-helper service,,,:/home/cups-pk-helper:/usr/sbin/nologin
    speech-dispatcher:x:111:29:Speech Dispatcher,,,:/var/run/speech-dispatcher:/bin/false
    whoopsie:x:112:117::/nonexistent:/bin/false
    kernoops:x:113:65534:Kernel Oops Tracking Daemon,,,:/:/usr/sbin/nologin
    saned:x:114:119::/var/lib/saned:/usr/sbin/nologin
    pulse:x:115:120:PulseAudio daemon,,,:/var/run/pulse:/usr/sbin/nologin
    avahi:x:116:122:Avahi mDNS daemon,,,:/var/run/avahi-daemon:/usr/sbin/nologin
    colord:x:117:123:colord colour management daemon,,,:/var/lib/colord:/usr/sbin/nologin
    hplip:x:118:7:HPLIP system user,,,:/var/run/hplip:/bin/false
    geoclue:x:119:124::/var/lib/geoclue:/usr/sbin/nologin
    gnome-initial-setup:x:120:65534::/run/gnome-initial-setup/:/bin/false
    gdm:x:121:125:Gnome Display Manager:/var/lib/gdm3:/bin/false
    li:x:1000:1000:li,,,:/home/li:/bin/bash
    root@li-System-Product-Name:/# 
    

      格式分析:

    root :x:0:0:root:/root:/bin/bash
    户名 :密码:用户id:用户组id:用户描述:用户目录:默认shell
    
    字段1 字段2 字段3 字段4 字段5 字段6 字段7
    root x 0 0 root /root /bin/bash
    户名 密码 用户id 用户组id 用户描述 用户目录 默认shell
      1-2-2.导言-用户管理-添加用户

      使用useradd命令。
      可用 man useradd命令来查看命令的帮助文件,由于内容比较长,建议用 man useradd > useradd.txt命令把内容重定向至名为useradd.txt的文件中,使用系统自带的文本编辑器来查阅。

    Usage: useradd [options] LOGIN
           useradd -D
           useradd -D [options]
    
    Options:
      -b, --base-dir BASE_DIR       base directory for the home directory of the
                                    new account
      -c, --comment COMMENT         GECOS field of the new account
      -d, --home-dir HOME_DIR       home directory of the new account
      -D, --defaults                print or change default useradd configuration
      -e, --expiredate EXPIRE_DATE  expiration date of the new account
      -f, --inactive INACTIVE       password inactivity period of the new account
      -g, --gid GROUP               name or ID of the primary group of the new
                                    account
      -G, --groups GROUPS           list of supplementary groups of the new
                                    account
      -h, --help                    display this help message and exit
      -k, --skel SKEL_DIR           use this alternative skeleton directory
      -K, --key KEY=VALUE           override /etc/login.defs defaults
      -l, --no-log-init             do not add the user to the lastlog and
                                    faillog databases
      -m, --create-home             create the user's home directory
      -M, --no-create-home          do not create the user's home directory
      -N, --no-user-group           do not create a group with the same name as
                                    the user
      -o, --non-unique              allow to create users with duplicate
                                    (non-unique) UID
      -p, --password PASSWORD       encrypted password of the new account
      -r, --system                  create a system account
      -R, --root CHROOT_DIR         directory to chroot into
      -s, --shell SHELL             login shell of the new account
      -u, --uid UID                 user ID of the new account
      -U, --user-group              create a group with the same name as the user
      -Z, --selinux-user SEUSER     use a specific SEUSER for the SELinux user mapping
          --extrausers              Use the extra users database
    
    

      初学之时,很难看懂帮助手册里的提示,不仅仅是英语语义和语序的障碍,尤其是对命令用法格式的逻辑没有理解。比如:

    useradd [options] LOGIN
    

      我的困惑之处在于,这个LOGIN到底是个什么鬼!最后经过瞎摸乱造,大概是清楚了,这个格式应该可以用中文翻译为:

    添加用户  [你要设置的选项放这里!]   你要添加的用户名写这里!
    

      下面进行简单的测试:

    li@li-System-Product-Name:/$ sudo useradd -c woyou10gelaopo hahaha
    li@li-System-Product-Name:/$ 
    
    li@li-System-Product-Name:/$ cat /etc/passwd
    .
    以上略
    .
    hplip:x:118:7:HPLIP system user,,,:/var/run/hplip:/bin/false
    geoclue:x:119:124::/var/lib/geoclue:/usr/sbin/nologin
    gnome-initial-setup:x:120:65534::/run/gnome-initial-setup/:/bin/false
    gdm:x:121:125:Gnome Display Manager:/var/lib/gdm3:/bin/false
    li:x:1000:1000:li,,,:/home/li:/bin/bash
    hahaha:x:1001:1001:woyou10gelaopo:/home/hahaha:/bin/sh
    
      1-2-3.导言-用户管理-删除用户

      内容

    相关文章

      网友评论

          本文标题:Linux系统基础001

          本文链接:https://www.haomeiwen.com/subject/xlqdjctx.html