Tuesday, March 17, 2020

Basic Unix Commands (1) Essays - System Administration, Passwd

Basic Unix Commands (1) Essays - System Administration, Passwd Jiang Li, Ph.D. Department of Computer Science CSCI 211 UNIX Lab Basic Unix Commands (1) Dr. Jiang Li Jiang Li, Ph.D. Department of Computer Science Todays Focus System login Directories and files Basic commands (directory and file related) id, passwd ls, chmod man cd, pwd Jiang Li, Ph.D. Department of Computer Science Logging in Connecting to a remote machine: Well connect to the Linux Server via SSH (available in putty) The servers address is 138.238.148.14 After connection, you are presented with a login prompt Input your username and password to login After logging in, youre placed in your home directory(where your personal files are located) Jiang Li, Ph.D. Department of Computer Science Putty Connection Interface Input the servers address in Host Name text box Choose SSH as the connection type Use the default port number 22 Click Open button to connect to the server Jiang Li, Ph.D. Department of Computer Science The Command Prompt After you login, you will see the command promptat beginning of each line You can type your commands after the command prompt A command consists of a command name and some option(s) called flag(s) In Unix and Linux, everything (including commands) is case-sensitive. Command promptCommand(optional) flags(optional) arguments Jiang Li, Ph.D. Department of Computer Science idCommand Users and Groups Linux is a multi-user/group system Each user belongs to one or more groups Each group contains one or more users id Get the information of the login account Users id, username, group id and groups names that the user belongs to Example [prompt] $ id uid=51931(hguo) gid=14082(cgroup761) groups=14082(cchome761),16207(admin_nonprod),16210(admin_ prod) Jiang Li, Ph.D. Department of Computer Science Setting a Password passwdcommand You can use passwdto change/setting a password for your account You need to input your old password for authentication, then input your new password two times Example [prompt] $ passwd Changing password for hguo. Enter login(LDAP) password: New password: Re-enter new password: Jiang Li, Ph.D. Department of Computer Science Directories In Unix, files are grouped together in places called directories, which are analogous to foldersin Windows Directory paths are separated by a forward slash: / Example: /home/scs/howard The hierarchical structure of directories (the directory tree) begins at a special directory called the root, or / Absolute paths start at / Example: /home/robh/classes/sycs211 Relative paths start in the current directory Example: classes/sycs211(if youre currently in /home/robh) Your home directory ~ is where your personal files are located, and where you start when you log in. Example: /home/yourusername Jiang Li, Ph.D. Department of Computer Science Directories (contd) Following symbolshave special meanings you need to know ~: Your home directory ..: The parent directory .: The current directory Jiang Li, Ph.D. Department of Computer Science Files File is a logical unit used to store users and/or system data Ultimately, Linux is a collection of files stored on the hard disk Filename Unix filenames are much like the filenames on other OS. But unlike Windows, Unix file types (e.g. executable files, data files, text files) are not determined by file extension (e.g. foo.exe, foo.dat, foo.txt) Many file-manipulation commands use only 2 letters e.g., ls, cd, cp, mv, rm, nl, etc. Jiang Li, Ph.D. Department of Computer Science List the Content lscommand One of the most frequently used command LiSts the contents (and their attributes) in a specified directory (or the current directory if no arguments are specified) Syntax: ls [args> ] Example: ls backups/ List the contents in backups directory Jiang Li, Ph.D. Department of Computer Science The lsCommand with -l ls l This command gives more information about the files present in the current directory. Jiang Li, Ph.D. Department of Computer Science Notes on access permissions Example: (a) drwxrwxr (b) -rwxr-x- First character: directory (d) or file (-). Then, 3 groups of 3 letters (total 9 letters) Owners permission, Group members, Others Within each group Readable (r) / Writable (w) / Executable (x) No permission is represented by a dash (-) Jiang Li, Ph.D. Department of Computer Science Notes on access permissions Example -rwxrwxrwx Everybody can read, write and execute the file Lowest security, highest accessibility -rw- Only the owner can read and write the file Highest security, lowest accessibility Jiang Li, Ph.D. Department of Computer Science chmod-Modify Permissions Syntax: chmod [OPTION] mode FILE/DIR Examples: chmod u+rwx myfile chmod go-w mydir Remove write permission on group&others for mydir directory r: readable w: writeable x: executable u: user g: group o: others +: assign -: remove Jiang Li, Ph.D. Department of Computer Science The lsCommand with -a ls a Using (-a) flag shows allfiles/sub-directories, including visible files and invisible files Invisible files filename start with dot sign e.g.: .profile, .bashrc, ., .. Jiang Li, Ph.D. Department of Computer Science Getting help with man man(short for manual) documents for commands man cmd> retrieves detailed information about cmd> man kkeyword> searches the short descriptions and manual pages for keyword(faster, and will probably give better results) fiji:~$ man k password Passwd (5) -password file