linking files and the inode

  • identifies files
  • permissions
  • ownership
  • date and time stamps
  • paths to data on file system
  • everything about the file except for the file name itself
1
2
someuser@somehost ~/workspace/someuser_/redhat_training > ls -li asdf
139117524 -rw-rw-r--. 1 someuser someuser 0 Nov 26 16:23 asdf

flag -i shows inode id 1 = one name pointing to that file

1
2
3
4
5
someuser@somehost ~/workspace/someuser_/redhat_training > ln asdf asdf2
someuser@somehost ~/workspace/someuser_/redhat_training > ls -li
total 0
139117524 -rw-rw-r--. 2 someuser someuser 0 Nov 26 16:23 asdf
139117524 -rw-rw-r--. 2 someuser someuser 0 Nov 26 16:23 asdf2

same inode, now there are 2, with same id, and both say there are 2 files pointing to that same id

if you have a program looking for a file, and it doesn’t exist, renaming the file might break something else, so link a new name to the existing file instead

have to create a link on the same file system with hard links

soft links allow you to create links across file systems, and they get new inodes

1
2
3
4
5
someuser@somehost ~/workspace/someuser_/redhat_training > ls -li
total 0
139117524 -rw-rw-r--. 2 someuser someuser 0 Nov 26 16:23 asdf
139117524 -rw-rw-r--. 2 someuser someuser 0 Nov 26 16:23 asdf2
139117525 lrwxrwxrwx. 1 someuser someuser 4 Nov 26 16:27 asdf3 -> asdf

lrwxrwxrwx the ‘l’ indicates it is a link

with soft link, removing file that is pointed to breaks the link, and accessing it by file pointed from results in empty file

until you delete a last file that points to an inode, the inode will continue to exist. hard links point to inodes, soft links point to other files

shell expansion

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
ls * # is default

ls ?file # match any single character, then 'file'

ls [ace]* # match OR whatever is in []

ls [^ace]* # match NOR whatever is in []

ls [[:alpha:]]* # show all files starting with alpha chars

ls [[:digit:]]* # show all files starting with digits`

also see alnum or punct

brace expansion

echo {Sun,Mon,Tues,Wednes}day.log Sunday.log Monday.log Tuesday.log Wednesday.log

sequences in brace expansion touch song{1..5} song1 song2 song3 song4 song5

use braces to specify the boundaries of a variable, but you don’t have to

variables

1
${MY_VAR} $MY_VAR

only needed for strings that combine variables with special characters, like underscores

1
2
$FIRST_$LAST # will fail with vars FIRST AND LAST
${FIRST}_${LAST} # will not

command substitution

backticks are older, not recommended

$() is preferred

double quotes are weaker, single quotes are strong (stronger because only need one of them); single quotes will not allow command substitution, double quotes will

prefixing special chars like $ with \ will take away the special meaning of the next character (escaping), this will prevent expansion in a double-quoted string

managing files (again)

cd - : take me to the previous working directory

getting help (man pages)

MAN(1) : the 1 is the ‘section’

1
2
3
4
5
man -k somestring # search for man pages

whatis something # show man page references

man something # shows first section matched; if `something` is in multiple sections, use `man 5 crontab`

anything in a man page in square brackets is optional

searching inside man pages is not case sensitive

1
2
3
4
5
6
7
export LESS='-X' # says don't clear the screen when exiting less
shift`+`g` # end of man page
g # beginning of man page
d # scroll down 1 half-page at a time
u # up 1 half-page at a time
/string # search for string, use `n` to go to next match
? # reverse search

section 8: daemons or administrative commands

getting help (info)

hyperlinks, less rigid than man pages

pinfo

eh, arrows don’t work, do i really need this anyway?

redirecting output

channel 0 : stdin channel 1 : stdout channel 2 : stderr channel 3+ : files

what does the & in 2>&1 mean?

there’s a more modern technique to redirect

write

1
ls /shoe /boot &> combined_2.log

append

1
ls /rav /var &>> combined_2.log

useful to hide errors from find when you don’t have permission to see it

1
find / -iname passwd 2> /dev/null

< to indicate input

tee command sends to stdout and saves to a file

1
2
somecommand | tee output_file
# tee -a` will append to the file instead

vim

modes

  • insert (i)
  • command (default)
  • extended command (:)
  • visual (v)

cw : change word, deletes word and puts you into insert mode

v : visual mode

ctrl+v : visual block mode shift+v : multiline mode

use vimtutor for interactive training tutorial

changing the shell environment

1
2
3
4
set # modify env
env # will not modify env
EXPORT # change env for all future commands
env MYVAR=some text # adds var MYVAR to current env

chapter 6: user and group concepts

1
2
3
whoami
id # show id details
/etc/passwd # has accounts on system

first char is x and represents password, which used to be stored here

/etc/group : has groups

1
2
3
4
someuser@somehost ~ > cat /etc/group | grep someuser
libvirt:x:00000:someuser
dockerroot:x:00000:someuser
docker:x:00000:someuser

user types:

  • superuser
  • system accounts
  • regular users

the super user

gets its power from being UID 0, not from being ‘root’

su : switch user

as root, you don’t need the password of the user you want to switch to

man page explains the significance of the - in su - , which just means start login shell

what is the /etc/shadow file?

1
2
3
4
visudo # is a thing, lets you edit the sudoers file, which can only be edited with the visudo command
%groupname # `%` is how group names are identified in the visudo file
use NOPASSWD # somecommand` for allowing specific commands without sudo
sudo -i` # logs you in as root user, gets shell, but you don't need to know the root user's password; but `su` requires you to know the password
1
2
3
4
5
someuser@somehost ~ > su -
Password:
su: Authentication failure
someuser@somehost ~ > sudo -i
root@somehost ~ >

managing local user accounts

1
2
3
4
5
useradd -- # `useradd` adds a user
userdel -- # `userdel` deletes a user, but by default will retain the directory; use -r; without -r, the inode will still exist with the user's old, but the id will be available for reassignment, so the next user created will have access to the previous user's files
usermod -- # changes properties of user
getent # name service switch libraries, can investigate details about users
groupadd -- # add groups

managing user passwords

/etc/shadow where hashed passwords are stored; first $ is the hash type, second $ is the salt value, third $ is the user’s password hash

also shows how long since, how long until change, how soon they can change again, how many days to warn, how many days they can log in after it expires, etc.

Numbers in the 17995 range are how many days since jan 1 1970

1
2
3
4
chage # used to change aging information for user's password
chage -l $USER # will show the details about the user's password
usermod -L # locks the account by putting a `!` in front of password hash
usermod -U # unlocks the account by removing the `!` from in front of the password hash

allocate a user a no-login-shell to prevent them from sshing to the system

1
2
3
less /etc/shadow # will show the `!` in front of the hashed password
useradd theusername -s /sbin/nologin` # sets the shell field of the /etc/passwd entry to `/sbin/nologin`, will show them 'This account is currently not available.'
# less /etc/login.defs # shows login defaults for new users