move dir fundamentals to basics

This commit is contained in:
Malin Freeborn
2020-01-05 21:06:49 +01:00
parent 4a6b551ad7
commit 2ab97c114d
22 changed files with 7 additions and 4 deletions

60
basics/archives.md Normal file
View File

@@ -0,0 +1,60 @@
# Automatic Backups with `find`
> find /home/"$(whoami)" -type f -size -2M | xargs zip -u backup
# Tar Archives
Create ze files:
> tar czf file.tar.gz file1 file2
Extract ze files:
> tar xzf file.tar.gz
The .tar extension means two or more files are bundled together into a single file. The .tar.gz means compression.
Tarballs come with a number of arguments.
- c means 'create'.
- v means 'verbose'.
- f means 'this is the file' and must always be the ultimate argument.
- z means compression.
So we can compress file1 and file2 into a single tar called 'archive' with:
> tar czvf archive.tar.gz file1 file2
Extraction uses 'x' instead of 'c'.
> tar xzvf archive.tar.gz
Create a very compressed file:
> tar cfj super-compressed.tar.gz file1 file2
# Example - Compressing all Latex Files in /home/
> sudo find ~ -maxdepth 4 -name "*.txt" | xargs tar cvf latex-bundle.tar.gz
# ssh backup
Back up an unmounted partition with ssh:
> sudo dd if=/dev/sda1 | ssh -C ghost@192.168.0.10 "dd of=/home/ghost/backup.img" status=progress
# img.xz
Install `xz`.
Unzip the image with:
> unxz void.img.xz
This then deletes the .xz file. To keep it:
> unxz --keep void.img.xz

34
basics/at.md Normal file
View File

@@ -0,0 +1,34 @@
`at` must be installed with:
> sudo apt-get install at
Then jobs can be specified with absolute time, such as:
> at 16:20
> at noon
> at midnight
> at teatime
The jobs can also be specified relative to the current time:
> at now +15 minutes
Finally, accept the jobs with ^D.
# Managing `at` Jobs
Display a list of commands to run with:
> atq
`2 Sat Oct 20 16:00:00 2018 a roach-1`
This will print all pending IDs. Remove a job by the ID with:
> atrm 2
Check /var/spool/cron/

152
basics/bash.md Normal file
View File

@@ -0,0 +1,152 @@
# STIN, STOUT, STERR
Input is 0, output is 1, error is 2.
Pipe standard output to log.txt while also outputting it.
> cat file.txt |& tee -a log.txt
Copy file and *if* that's successful, delete it where it stands.
> scp archive.tar.gz pi@192.168.0.31:/home/pi && rm archive.tar.gz
A double pipe will try one, and do the other if that fails.
> cp -r ~/Archive ~/Backup || tar czf Archive.tar.gz *
# REGEX
Regular expression characters include:
\\ ^ $ . | ? * + () [] {}
As a result, grep cannot read these characters as literal characters unless they are escaped. E.g.
> grep wtf\? log.txt
... will search the string 'wtf?' in the file log.txt. Another version is egrep (now used with 'grep -e') which uses more characters as special characters, or fgrep, which treats all characters as literal strings.
# Environmental Variables
PWD, USER, PATH
To display all environmental (but not local) variables, use
> env
Set a variable with
> colour=red
Display your variable with
> echo $colour
Export this to the entire system using:
> export colour=blue
# Search commands
> apropos cat
# Working with Text
Convert every tab to ten spaces.
> expand -t 10 file.txt
Or the reverse, with 3 spaces converting to a tab.
> unexpand -t 3 file.txt
Format a file by cutting text after 60 characters.
> fmt -w 60 file.txt
Indent all but the first line of a paragraph.
> fmt -t file.txt
Look at the new lines of a file only:
> tail -f /var/log/syslog
The sort function arranges lines alphabetically. Use -r to reverse and -n to sort by number.
# Sed
> sed -i s/hey/hoi/g greetings.txt
Edit all examples of hey to hoi in greetings and print that to the file.
# Measurement
Measure how long a script takes for super-autism powers.
> time [bash script]
# Functions
> function my_funct(){ do_thing $1; }
Remove a function with
> unset my_function
# Paths
Every shell has various paths from where it can execute binary files. Find out your current one with:
> echo $PATH
To add a directory to a path, e.g. /usr/share/bin, you can declare it in addition to the old path with:
> PATH=$PATH:/usr/share/bin
And then check it by echoing the path again.
Before this, probably best to check the path exists with:
> if [ -e /usr/share/bin ]; then
> echo yes
> fi
# Pipes, Pedantry and Brackets
Things that [[ ]] statements can do which [ ] statements cannot:
- Intuitive and easy 'and' statements.
- [[ -z $var && -d ~/LK ]]
- Intuitive and easy 'or' statements.
- [[ -d LK || -f ghost-backup.zip ]]
- Simple expression comparisons
- [[ $v1 > $v2 ]]
- Simple expression comparisons with clumsy strings
- [[ item-1 > item-2 ]]
- Vague comparisons
- [[ $answer =~ ^y(es)?$ ]]
# exec
exec will start a process running as just that process. In a bash script, the line:
> unison rat
... will startup `unison` as a sub-process of bash. But:
> exec unison rat
... starts unison as its own process.
# Brace expansion
> mv picture{,-1}.jpg
This expands to
> mv picture.jpg picture-1.jpg
# `for` Statements
for f in *tiff;do
convert "$f" "${f/.tiff/.png}"
done

249
basics/basics.md Normal file
View File

@@ -0,0 +1,249 @@
# Absolute Bloody Basics
You need about a dozen commands to move around Linux.
After that, you look up the rest as you go.
Don't worry about understanding any of it, just type it in and the habit forms pretty quickly.
You start in a dark room. You have a 'look-see' what's in front of you:
> ls
If you get no response, the list of items is "", meaning "nothing here".
Have a look at **a**ll the files:
> ls -a
`. ..`
So `.` means 'here' and `..` means 'you see stairs leading downwards'.
Find out where you are by **p**rinting out your **c**urrent '**d**irectory' (i.e. 'location'):
> pwd
Change directory (`cd`) down one level:
> cd ..
Look where you are again with `pwd`, then go back up. Use `ls`, and if you see `bob`, then:
> cd bob
Move around the directories. The place at the bottom is the 'root', and is known as `/`. Go to the root:
> cd /
Do `ls` again and change into `etc`. Look at how much space those folders are taking up:
> du iptables
That's the number of kilobytes the file is taking up. Do the same again, but in a human-readable format:
> du -h iptables
The `du` program has `-h` for 'human', '-s' for 'short', and a bunch of other commands. Have a look at the manual and try another command:
> man du
Once you're done, press 'q' to quit the manual page and try the extra `du` flag you've found.
Now you can try to gain super-powers and take over the system:
> sudo -i
At this point, you are 'root'. All your commands will be executed, even if they're unsafe, or even if you ask to delete the entire machine. Best to exit out of the root account:
> exit
Go find a file that isn't a directory. You can tell which is which with:
> ls -l
A directory starts with a 'd', like this:
`drwxr-xr-x 79 root root 4096 Jan 3 05:15 /etc/`
A standard file starts with '-', like this:
`-rw-r--r-- 1 root root 8 Dec 11 17:26 hostname`
Look inside the file /etc/hostname to find out your computer's name:
> cat /etc/hostname
Print out the words "hello world":
> echo "hello world"
Move back to your home directory:
> cd
Take the words 'hello world', and put them in 'my_file':
> echo 'hello world' > my_file
Measure the disk usage of that file, then put the results at the bottom of the file:
> du my_file >> my_file
And check the results:
> cat my_file
# Autocompletion
Press tab after typing a few keys and bash will guess what you're trying to type.
# Permissions
Look at your file's owner:
> ls -l my_file
If it says `-rw-r--r-- 1 root root 8 Dec 11 17:26 hostname` then the file is owned by 'root'.
Take your file and change the owner to root:
> sudo chown root my_file
Change the same file so it's owned by the group 'audio':
> sudo chown :audio my_file
Check you did that correctly:
> ls -l my_file
`-rw-r--r-- 1 root audio 0 Jan 3 19:20 my_file`
Read the start of that line. Root can 'read' and 'write' to or delete the file. Try to remove (delete) it:
> rm my_file
You'll see you're not allowed, because you don't own it.
Look at which groups you're in:
> groups
Change the file so that members of the audio group can write to the file:
> sudo chmod g+w my_file
Check you got it right with `ls -l`:
> -rw-rw-r-- 1 root audio 0 Jan 3 19:20 my_file
Try to delete the file again:
> rm my_file
If you can't, you're not in the audio group. Add yourself. You'll need to *modify* your *user account*, by **a**ppending 'audio' to your list of groups.
Use `-a` to **a**ppend, and `-G`, to say you're modifying groups:
> sudo usermod -a -G audio [ your username here ]
Now you should be able to remove (delete) the file. Remember, that using 'rm file' will not send it to a recycling bin. The file is gone.
# Directories
Make a directory called 'new test':
> mkdir 'new test'
Make two directories, called 'A', and 'Z':
> mkdir A Z
# Text Searches
Measure the disk usage of everything ('\*' means 'everything'), and put it in a file called 'disk usage.txt':
> du -sch * > A/'disk usage'.txt
Look at your file:
> cat A/'disk usage.txt'
If you think you have too much information, use `grep` to just get the one line of text you want:
> grep total A/disk\ usage.txt
The `grep` program also has a manual ('man page'). You should find out what that `-c` flag does, but the manual is too long to read.
Start the manual:
> man du
Then search for `-c` by pressing `/`. Your final keys should be `man du`, then `/-c`
Find out if the `ls` program also has a 'human readable' format by using `grep` to search for the word 'human':
> man ls | grep human
Now use that flag that you've found in combinatin with the `-l` flag to look at a file.
Remove the directory 'Z':
> rmdir Z
Remove the directory 'Z':
> rmdir Z
And then remove all the rest:
> rmdir *
The 'A' directory will not budge because it's not empty. Remove it recursively, so the computer will remove the things inside the directory as well as the directory itself:
> rm -r A
# Installation
You get a package manager which installs programs, fonts, et c.
If you're on something like Debian, you'll have `apt`, or if you're on something like Red Hat, you'll have `yum`.
If unsure, ask where a program is:
> whereis yum
> whereis apt
If you get a hit, you can use whatever program that is to install things.
Set a reminder of your package manager:
> echo my package manager is yum | lolcat
If that failed it's because you don't have `lolcat` installed.
Install lolcat:
> sudo apt install lolcat
Try the same command again.
Search for things you want, like `libreoffice`, or `gimp`:
> apt search libreoffice
... then install one of them with:
> apt install [ thing ]
Remove `lolcat`, because it's useless:
> sudo apt remove lolcat
... and that's pretty much it. You can move, create, destroy, install things, and look things up.
# Review
- Search for random things with your package manager and install the interesting ones.
* Read the manual with `man thing`
* If it's useless, remember to uninstall it.
- Have a look around the file system in `/`.
- Look in the `.config` folder in your home directory.
* If you copy a program's config to another machine, the program will behave just like you set it up in your own machine.

98
basics/boot.md Normal file
View File

@@ -0,0 +1,98 @@
# Basic Startup
BIOS > MBR > GRUB > Kernel > Init > Run Level
- The BIOS identifies system hardware.
- The Master Boot Record contains partition and filesystem data.
- The Grand Unified Bootloader executes the kernel.
- The Init Executes designates run level (via SysVinit, Upstart, or Systemd).
- Run Level starts the user's session.
The Master Boot Record is a 512 byte file called boot.img which starts the first sectore of core.img into memory (GRUB Stage 1.5), which then executes /boot/grub.
# Access system
Ctrl+c at boot then add in
> rw init=bash
# Run Levels
0: Half
1: Single user mode
2: Multi-user, without NFS
3: Full multi-user mode
4: Unused
5: X11
6: Reboot
None of this is used by humans anymore - it's all systemd.
# Systemd
See what's running with ....
> systemctl list-units
Stop, start, whatever with:
systemctl enable|stop|start httpd
This starts httpd (Fedora's word for Apache2).
# Boot Records
'File System Tab' under /etc/fstab keeps track of the partitions and boot order.
The logical voluem manager (LVM) can make non-hardware partitions.
The nomenclature is:
- PV = physical volume
- LV = logical volume
- VG = volume group
# Volume Groups
> sudo vgcreate work-volume /dev/sdb2 /dev/sdb4
This creates the volume group 'work-volume', consisting in sdb2 and sdb4.
Now you ahve a volume group, you can use it as part of a new logical volume.
> sudo lvcreate -n noob-lv work-volume
Then scan for all logical volumes on the system with lvscan.
> sudo lvscan
# GRUB
Install a grub with either:
> sudo grub-install /dev/sda
or
> sudo grub2-install /dev/sda
This takes all settings from /etc/fstab.
Then when done editing settings update the script in /boot/grub/grub.cfg (in Debian) or /boot/boot/grub/menu (in other systems).
There are default examples in /etc/grub.d/ (but not on Ubuntu).
Finalize your settings with grub-mkconfig (or grub2-mkconfig), or update-grub.
# Cowardice
If you can't do that, use boot-repair:
> help.ubuntu.com/community/Boot-Repair

34
basics/clock.md Normal file
View File

@@ -0,0 +1,34 @@
# Basics
Show system time:
> date
Show hardware time:
> sudo hwclock -r
Change system time to match hardware time:
> sudo hwclock --hctosys
Change hardware time to match system time:
> sudo hwclock --systohc
Manually set the hardware time to a specified date:
> sudo hwclock --set --date="8/25/19 13:30:00"
# Network Time Providers
Servers which take their time from an observatory we call Stratum 1 servers. Servers which takes their time from Stratum n servers are Stratum n+1 servers.
Install ntp with:
> sudo apt-get install -y ntp
The shell command for this is `ntpq`. Monitor the service providers using:
> ntpq -p

83
basics/conditionals.md Normal file
View File

@@ -0,0 +1,83 @@
# If statements
Test statement equality as so:
```
read t1
read t2
if test $t1 != $t2; then
echo 'variables do not match'
else
echo 'variables match'
fi
exit 0
```
# Case Structure
These deal with multiple states rather than forking conditions.
Example:
```
#!/bin/bash
# Simple case demonstration
echo "What's your favourite creature?"
read CRE
case $CRE in
human | humanoids ) echo "Why is $CRE always standard?"
;;
troll | monsters ) echo "Not exactly known for their character ..."
;;
owlbears | monsters ) echo "Really you're a wizard fan"
;;
esac
# While and Until
This prints from 10 until 2.
> declare -i COUNTER
> COUNTER=10
> while [ $COUNTER -gt 2 ]; do
> echo The counter is $COUNTER
> COUNTER=COUNTER-1
> done
> exit 0
```
There's also 'until', which stops when something is true, rather than keeping going when something is true.
# For
> for i in $( ls ); do
> du -sh $i
> done
# Sequences
The sequences tool counts up from X in jumps of Y to number Z.
Count from 1 to 10.
> seq 10
Count from 4 to 11.
> seq 4 11
Count from 1 to 100 in steps of 5.
> seq 1 5 100

42
basics/cron.md Normal file
View File

@@ -0,0 +1,42 @@
Anacron manages crontabs which might not have run because the machine was turned off. The first value shows the days between runs, the second shows how many minutes to wait after a boot to run.
For example:
> cat /etc/anacrontab
`7 15 cron.daily run-parts --report /etc/cron.daily`
This would run crontab every 7 days, and wait 15 minutes until after boot to run.
Various services from cron exist, e.g.
> sudo apt -y install cronie
start the cronie with
> sudo systemctl start cronie
start a cron with
> cron -e
You can run a script with:
*/10 * * * * /home/pi/script.sh
... which would run every 10 minutes.
To run something as root, do:
> sudo crontab -e
For example, you can update the database, meaning searches with 'locate' command will be faster.
> */30 * * * * /usr/bin/updatedb
# Testing with runparts
Run-parts runs all executable scripts in a directory.
> run-parts /etc/cron.hourly

12
basics/kernel.md Normal file
View File

@@ -0,0 +1,12 @@
# Living Space
Kernel modules live in lib/modules/$(uname -r)
Load them with
> sudo modprobe ath9k
Or remove one with
> sudo modprove uvcvideo

15
basics/keyboard.md Normal file
View File

@@ -0,0 +1,15 @@
# Set Layout
Set layout to British English.
> setxkbmap -layout gb
| Language | short |
|:--------|:------|
| Polish | pl |
| Serbian | rs |
Set 'alt + shift', as the command which cycles through the British English, Polish and Serbian keyboard layout.
> setxkbmap -layout gb,pl,rs -option grp:alt_shift_toggle

10
basics/kill.md Normal file
View File

@@ -0,0 +1,10 @@
# Basic Signals
To see an ordered list of termination signals:
> kill -l
1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL 5) SIGTRAP
6) SIGABRT 7) SIGBUS 8) SIGFPE 9) SIGKILL 10) SIGUSR1
11) SIGSEGV 12) SIGUSR2 13) SIGPIPE 14) SIGALRM 15) SIGTERM

8
basics/links.md Normal file
View File

@@ -0,0 +1,8 @@
Link from X to Y.
> ln -s X ../otherdir/Y
Links cause ownership headaches. Solve this with -h:
> chown -h user1 mysymlink

40
basics/locale.md Normal file
View File

@@ -0,0 +1,40 @@
A list of supported locales is available at /usr/share/i18n/SUPPORTED
See a full list with:
> cat /usr/share/i18n/SUPPORTED
Take the first portion to generate full locale information for a region:
> locale-gen ru_RU.UTF-8
Then use this for the current shell session with
> LANG=ru_RU.utf8
Expand this to the entire system with:
> export LANG=ru_RU.utf8
You can make this permanent for one user by adding this line to the ~/.profile or ~/.bashrc.
Make it permanent for the entire system by editing:
> sudo vim /etc/defaults/locale
# Variables
While generally set together, the variables setable are:
| Variable | Description |
|:-------------:|:------------|
| LC_TIME | Date and time |
| LC_NUMERIC | Nonmonetary numeric formats |
| LC_PAPER | A4 vs wrong paper |
| LC_ADDRESS | Address formats, for those amazingly concise Polish addresses. |
| LC_TELEPHONE | Telephone number formats. |
| LC_MEASUREMENT | Metric or Imperial, but no Impetric available. |
| LC_IDENTIFICATION | Metadata about the locale information |
| LC_ALL | Just everything at once. |

24
basics/locating.md Normal file
View File

@@ -0,0 +1,24 @@
# Whereis the Program
Ask where the `angband` program is, along with all its configuration files:
`whereis angband`
Also `which` shows where a binary file (the program) is,
> which cmus
`type` shows what kind of thing you're running, be it an alias, or binary program.
> type cmus
# Quick Search for Files
You'll need to set up `locate` for this by installing `mlocate`. `mlocate` needs a list of all files on the machine, so run:
> sudo updatedb
Then to find a file called 'my-cats.jpg', run:
> locate cats

57
basics/logs.md Normal file
View File

@@ -0,0 +1,57 @@
# Syslog Management Protocols
Let's look at the programs filling in things on our /var/log/ directory.
* rsyslog (common)
* syslog (old)
* syslog-ng (lots of content-based filtering)
* klogd (kernel-focussed)
# `rsyslog`
The config rests in /etc/rsyslog.conf, which then references /etc/rsyslog.d/.
# Systemd
This thing makes its own logs with journald, and the journal's own logging system writes to /var/log/journal/ directory, which is then filled with nonsense.
You can obtain nonsense in systemd's own format by entering:
journalctl -e
This thing generates so much nonsense it can crash your system, but can at least be checked with:
> journalctl --disk-usage
... in case you can't remember the `du` command.
You can limit the nonsense by editing the /etc/systemd/journald.conf file, and finding `#SystemMaxFileSize=`
# Logger
You can log things at any time with the logger:
> logger Server is being a dick!
Put things into a specific log with `-p`. They can enter into, e.g., lpr (printer) log file with a priority of "critical", with:
> logger -p lpr.crit Help!
Logfiles rotate around and eventually get deleted. Rotation means they get compressed.
Edit the config in /etc/logrotate.conf.
A few apps have their own special log rotation rules, kept in /etc/logrotate.d/.
The major variables to change are `weekly`, which compresses log files weekly, and `rotate 4`, which keeps 4 weeks worth of backlogs before deletion.
# Force Log Rotation
> sudo systemctl kill --kill-who=main --signal=SIGUSR2 systemd-journald.service
or just
> sudo systemctl restart systemd-journald.service

48
basics/packages.md Normal file
View File

@@ -0,0 +1,48 @@
# Looking
Your package has something to do with unzipping. Find out more:
> apropos unzip
# Maintenance
> dpkg -l
List what's installed.
# Libraries
Libraries under /lib/ typically contain an .so suffix when they're dynamic. It means 'shared object' as a number of programs will refer to it.
Others will have an /a/ suffix, meaning that they're static, and will be loaded at runtime.
We can check the dependencies of a program using the ldd command upon anything in a library. For example:
> ldd/usr/bin/md5sum
... shows us that md5sum depends upon:
- linux-vdso.so.1
- libc.so.6
- lib64/ld-linux-x86-64.so.2
To list all libraries, run:
> ldconfig -p
For example, if looking at /usr/lib/x86_64-linux-gnu/libXcomposite.so.1, we might wonder what it's for. We can then run:
> ldconfig -p | grep libXcomposite
... and find out nothing except that it redirects /usr/lib/x86...
So at least we know where it is.
> ldconfig -p | grep usb
... this will show where things which nominally relate to usbs live.
You can add to the libarary path by putting just any text file in /etc/ld.so.cache, e.g. in Arch where the path to the fakeroot environment is placed there.

74
basics/processes.md Normal file
View File

@@ -0,0 +1,74 @@
# Free
See free space with:
> free
and make it human readable with:
> free -h
Or `-m` for megabytes.
# Proccesses
See running items in current terminal with
> ps
or more with
> ps -a
Or the entire system with
> ps -e
Or the entire system with more information, BSD style, with:
> ps aux
And then search for a particular program with
> ps aux | grep cmus
# Jobs
Pause a job with ^z. Put it in the background with the '&' suffix.
List jobs in the current shell with
> jobs
And then you can pull number 1 up again with
> fg 1
Or continue running a stopped job with:
> bg 1
# Nice
This changes how nice a program is, from -20 to 19.
Install a program, but nicely, at nice value '10':
> nice -10 sudo apt -y install libreoffice
Aggressively use Steam, with a nice value of '-13'.
> nice --13 steam&
Find out that Steam's fucking everything up, so you change its nice value with 'renice':
> renice --5 -p 3781
Nerf all of roach-1's processes:
> renice 10 -u roach-1
... or the entire group
> renice -14 -g hackers

36
basics/shell.md Normal file
View File

@@ -0,0 +1,36 @@
# Shells
Dash - fast but limited funcionality, great for scripts.
sh - primitive and ubiquitous.
bash - the standard
elvish - user-friendly, but new, with a full file-browser embedded into the system.
# Login
All shells launch either as login or non-login. All remote sessions without a GUI withl require authentication, and therefore will be login.
## Login
These shells start by reading /etc/profile then the first of ~/.bash_profile, ~/.bash_login or ~/.profile, and load all given values.
## Non-Login
Non-login shells will read /etc/bash.bashrc and then the ~/.bashrc file. You can summon the different shell perameters with the command `.`.
For example, so summon the file ~/.bashrc, you can perform:
`. ~/.bashrc`
How the logout is handled depends upon ~/.bash_logout
# Defaults
The default shell config files to create for a new user are under /etc/skel.
# Shellcheck
Run `shellcheck script.sh` on your scripts to check them for mistakes.

45
basics/swap.md Normal file
View File

@@ -0,0 +1,45 @@
# Making a Swap File
> sudo mkdir -v /var/cache/swap
> cd /var/cache/swap
> sudo dd if=/dev/zero of=swapfile bs=1K count=4M
This creates a swapfile of (1k x 4M) 4 Gigs.
Change 4M to XM for an XGig swap.
> sudo chmod 600 swapfile
> sudo mkswap swapfile
> sudo swapon swapfile
Test it's working with top
> top -bn1 | grep -i swap
or:
> echo "/var/cache/swap/swapfile none swap sw 0 0" | sudo tee -a /etc/fstab
Test it'll work at boot with:
> sudo swapoff swapfile
> sudo swapon -va
# Partition Swaps
Put this in /etc/fstab:
`UUID=blah-blah none swap sw 0 0`
Then test it works with:
> sudo swapon -va
Test other partitions in fstab with:
> sudo mount -a

62
basics/time.md Normal file
View File

@@ -0,0 +1,62 @@
# systemd
Set time to synchronize with an ntp server:
> timedatectl set-ntp true
This info stays in /usr/share/zoneinfo
# Local Time
Local time is kept in /etc/localtime.
According to Dave's LPIC guide, you can set the local time by making asymboling link from your timezone to /etc/localtime, as so:
> sudo ln -sf /usr/share/zoneinfo/Europe/Belgrade /etc/localtime
...however this produced the wrong time for me. Further, /etc/localtime produces an output with cat, while the zoneinfo files do not.
# Locale
See local time, language and character settings with:
> locale
List available locales with:
> locale -a
To see additional locales which are available (but not necessarily installed):
> cat /usr/share/i18n/SUPPORTED
Set a supported locale with:
> locale-gen pl_PL.UTF-8
Then set that language, with:
> LANG=pl_PL.UTF-8
... then reboot.
# Network Time Protocol
Enter the shell with:
> ntpq
Or just glimpse and overview with:
> ntpq -q
This clock can drift, which is then listed under /var/log/ntp.drift
The config is under /etc/ntp.conf. If a line for the stats directory is listed, it'll log stats, e.g.:
`statsdir /var/log/ntpstats/`
This can show if clock drift occurs.
The config file also lets you specify servers to obtain time from.

204
basics/users.md Normal file
View File

@@ -0,0 +1,204 @@
# Basic Information
Let's get some entries with 'getent', e.g. passwd or group.
> getent passwd
> getent group
Obviously:
> getent shadow
will require sudo.
## Examples
> sudo adduser maestro
add user 'maestro'
This depends upon the settings in the /etc/default/useradd file and /etc/login.defs
> sudo useradd -m pinkie
add user 'pinkie' with a home directory
> sudo adduser -m -e 2017-04-25 temp
add expiry date to user
> userdel maestro
delete maestro
> userdel -r maestro
delete maestro and hir homefolder
> groups
find which group you are in
> id
same
> id -Gn maestro
Find which groups maestro is in
> deluser --remove-home maestro
delete user maestro
> usermod -aG sudo maestro
add user maestro to group sudo
> cat /etc/passwd
list users' passwords (and therefore users)
> groupadd awesome
create the group 'awesome'
passwords are stored in /etc/shadow.
there are user accounts for processes such as 'bin' and 'nobody' which are locked, so they're unusable.
> passwd -l bin
lock the user 'bin'
> more /etc/passwd | grep games
we find the name, password and user id of the user 'games'. I.e. the password is 'x', and the user id is '5'. The password is an impossible hash, so no input password could match.
> groupdel learners | delete the group 'learners'
> gpasswd -d pi games | remove user 'pi' from the group 'games'
> id games
find the id number of group 'games' (60)
> usermod -aG sudo maestro
add user to group 'maestro'
user info is stored in /etc's passwd, shadow, group and gshadow
# Defaults
The default new user profiles are under /etc/skel.
# Shells
A list of shells is in /etc/shells.
Only root can run shells not listed in /etc/shells
To change a user's shell:
usermod --shell /bin/bash user1
Alternatively, change the shell in /etc/passwd.
Usermod also lets you change a user's username:
> usermod -l henry mark
However, this will not change the home directory.
Lock a user out of an account:
usermod -L henry
# More Arguments
-G or -groups adds the user to other groups:
> usermod -G sudo henry
-s adds the user to a shell.
-u let's you manually specifiy a UID.
# Groups
In /etc/group, a group file may look like this:
`sudo:x:27:mike,steve`
We can use groupmod, like like usermod, e.g. to change a name:
> groupmod -n frontoffice backoffice
Delte a group:
> groupdel frontoffice
# Logins
See list of logged on users.
> w
See last logons:
> last
or all logon attempts, including bad attempts:
> lastb
List recently accessed files:
> last -d
See files opened by steve
> lsof -t -u steve
See files opened by anyone but steve
> lsof -u ^steve
Fuser can also track people loggingin:
> fuser /var/log/syslog
... and fuser can kill everything accessing the home directory:
> fuser -km /home
# Looking for Dodgy Files
Some files can be executed by people as if they had super user permissions, and that's okay... sometimes.
Let's start with files executable by user:
> sudo find / -type f -perm -g=s -ls
And then those executable by the group:
> find / -type f -perm -g=s -ls
And finally, worrying files, executable by anyone as if sie were the owner:
> find / -xdev \( -o -nogroup \) -print
Then have a look at resource usage per user.
#SGID
> sudo chmod u+s process.sh
This will modify process.sh to that instead of being simply executable, anyone executing it will have the permissions as if owner while executing it.

63
basics/wifi.md Normal file
View File

@@ -0,0 +1,63 @@
# Netstat Stuff
Stats on local net usage within domain.
> iftop -p -n
> whois domain.com
Info on domain, whether it's taken, et c.:
> dig domain.com
> ifconfig
Versatile wifi tool:
> nmcli
# Examples
You want to connect to the internet.
> sudo iwconfig
Get knowledge of wireless state. The output might be:
`wlp3s0 IEEE 802.11 ESSID:"Gandalf WajFaj"`
`Mode:Managed Frequency:2.412 GHz Access Point: 10:05:01:90:AC:1A`
`Bit Rate=144.4 Mb/s Tx-Power=15 dBm`
`Retry short limit:7 RTS thr:off Fragment thr:off`
`Encryption key:off`
`Power Management:on`
`Link Quality=64/70 Signal level=-46 dBm`
`Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag`
`Tx excessive retries:0 Invalid misc:363 Missed beacon`
This tells you that your ESSID is 'Gandalf WajFaj', and the access point name is 10:05:......
> nmcli radio
You get an overview of your radio devices. You're told that eth0 deals with your ethernet and wlan0 deals with wifi. wlan0 is a file which represents your wifi device.
> nmcli wlan0 wifi rescan
> nmcli device wifi list
Now to connect.
> nmcli device wifi connect [SSID] [your password] [wifi password]
Alternatively, you can use
> nmcli -ask device wifi connect [SSID]
And it'll ask for your password, so you're not typing it in in full view.