modify basic filestructure
It's unclear what's 'basic', so `basic/` notes have been mostly moved. The remainder became `shell/`.
This commit is contained in:
77
system/at.md
Normal file
77
system/at.md
Normal file
@@ -0,0 +1,77 @@
|
||||
---
|
||||
title: "at"
|
||||
tags: [ "basics", "time" ]
|
||||
---
|
||||
Install with:
|
||||
|
||||
```sh
|
||||
sudo apt install at
|
||||
```
|
||||
|
||||
Enable the daemon service with:
|
||||
|
||||
```sh
|
||||
sudo systemctl enable --now atd
|
||||
```
|
||||
|
||||
Then jobs can be specified with absolute time, such as:
|
||||
|
||||
```sh
|
||||
at 16:20
|
||||
```
|
||||
|
||||
```sh
|
||||
at noon
|
||||
```
|
||||
|
||||
```sh
|
||||
at midnight
|
||||
```
|
||||
|
||||
```sh
|
||||
at teatime
|
||||
```
|
||||
|
||||
Type in your command, e.g.:
|
||||
|
||||
```sh
|
||||
touch /tmp/$FILE.txt
|
||||
```
|
||||
|
||||
The jobs can also be specified relative to the current time:
|
||||
|
||||
```sh
|
||||
at now +15 minutes
|
||||
```
|
||||
|
||||
Finally, accept the jobs with ^D.
|
||||
|
||||
# Managing `at` Jobs
|
||||
|
||||
Display a list of commands to run with:
|
||||
|
||||
```sh
|
||||
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:
|
||||
|
||||
```sh
|
||||
atrm 2
|
||||
```
|
||||
|
||||
Check `/var/spool/atd/` to see the jobs.
|
||||
|
||||
## Automation
|
||||
|
||||
Automatically add a job for later, by setting the date, then using echo for the command.
|
||||
|
||||
```sh
|
||||
t="$(date -d "2 minutes" +%R)"
|
||||
echo "fortune > ~/$FILE" | at "$t"
|
||||
watch cat $FILE
|
||||
```
|
||||
|
||||
The `$t` here outputs the day in minutes, but you could also do `t="$(date -d "2 days" +%m/%d/%Y)"`.
|
||||
67
system/clock.md
Normal file
67
system/clock.md
Normal file
@@ -0,0 +1,67 @@
|
||||
---
|
||||
title: "clock"
|
||||
tags: [ "basics", "time" ]
|
||||
---
|
||||
|
||||
Show system time:
|
||||
|
||||
```sh
|
||||
date
|
||||
```
|
||||
|
||||
Show hardware time:
|
||||
|
||||
```sh
|
||||
sudo hwclock -r
|
||||
```
|
||||
|
||||
Change system time to match hardware time:
|
||||
|
||||
```sh
|
||||
sudo hwclock --hctosys
|
||||
```
|
||||
|
||||
Change hardware time to match system time:
|
||||
|
||||
```sh
|
||||
sudo hwclock --systohc
|
||||
```
|
||||
|
||||
Manually set the hardware time to a specified date:
|
||||
|
||||
```sh
|
||||
sudo hwclock --set --date="8/25/19 13:30:00"
|
||||
```
|
||||
|
||||
## Normal Date
|
||||
|
||||
```sh
|
||||
date +%d/%m/%y
|
||||
```
|
||||
|
||||
# Unix Time
|
||||
|
||||
Computers started counting time on January 1st, 1970, and added one second-per-second. If your clock shows you're in the 70's, it's reset to the start.
|
||||
|
||||
Track the time in Unix-time:
|
||||
|
||||
```sh
|
||||
date +%s
|
||||
```
|
||||
|
||||
# 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:
|
||||
|
||||
```sh
|
||||
sudo apt-get install -y ntp
|
||||
```
|
||||
|
||||
The shell command for this is `ntpq`. Monitor the service providers using:
|
||||
|
||||
```sh
|
||||
ntpd -q
|
||||
```
|
||||
|
||||
38
system/hard_links.md
Normal file
38
system/hard_links.md
Normal file
@@ -0,0 +1,38 @@
|
||||
---
|
||||
title: "hard links"
|
||||
tags: [ "basics", "links" ]
|
||||
---
|
||||
|
||||
A hard link is one file which exists in multiple locations.
|
||||
|
||||
Each file has an ID, which is kept on the hard disk's partition.
|
||||
Each hard link has the same ID, because they are the same file.
|
||||
This ID is called the 'inode'.
|
||||
|
||||
Create a file, and a hard link:
|
||||
|
||||
```sh
|
||||
fortune > $file_1
|
||||
mkdir -p x/y/z/
|
||||
ln $file_1 x/y/z/$file_2
|
||||
```
|
||||
Have a long look at the file with the `-l` flag, and check the inode with `-i`:
|
||||
|
||||
```sh
|
||||
ls -li $file_1 x/y/z/$file_2
|
||||
```
|
||||
|
||||
Since they are the same file, you can make a change to one, and it changes both:
|
||||
|
||||
```sh
|
||||
fortune | tee x/y/z/$file_2
|
||||
cat $file_1
|
||||
cat x/y/z/$file_2
|
||||
```
|
||||
|
||||
# Danger Zone
|
||||
|
||||
- hard links will not work on directories, only standard files and fifos.
|
||||
- `git` will destroy and remake files, so it will not respect hard links.
|
||||
- Files cannot have a hard link on another disk partition, because the inode is stored on each partition.
|
||||
|
||||
74
system/kill.md
Normal file
74
system/kill.md
Normal file
@@ -0,0 +1,74 @@
|
||||
---
|
||||
title: "kill"
|
||||
tags: [ "basics" ]
|
||||
---
|
||||
|
||||
If you want to kill a program in a graphical environment, open a terminal and type:
|
||||
|
||||
# Graphical Programs
|
||||
|
||||
```sh
|
||||
xkill
|
||||
```
|
||||
|
||||
Then click on the application which you want to kill.
|
||||
|
||||
# All Programs
|
||||
|
||||
To kill a program, find it with:
|
||||
|
||||
```sh
|
||||
pgrep discord
|
||||
```
|
||||
|
||||
This will give you the UUID, e.g. `19643`.
|
||||
|
||||
Kill the program with:
|
||||
|
||||
```sh
|
||||
kill 19643
|
||||
```
|
||||
|
||||
# Types of Kill
|
||||
|
||||
To see an ordered list of termination signals:
|
||||
|
||||
```sh
|
||||
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
|
||||
|
||||
|
||||
You can select these levels with a '- number'.
|
||||
Higher numbers are roughly equivalent to insistence.
|
||||
|
||||
For example:
|
||||
|
||||
```sh
|
||||
kill -1 3498
|
||||
```
|
||||
|
||||
This roughly means 'maybe stop the program, if you can, maybe reload'.
|
||||
|
||||
Or the famous:
|
||||
|
||||
```sh
|
||||
kill -9 3298
|
||||
```
|
||||
|
||||
This means 'kill the program dead, now, no questions, dead'.
|
||||
|
||||
**Beware** - if Firefox starts another program to connect to the internet, and you `kill -9 firefox`, this will leave all of Firefox's internet connection programs ("children") still there, but dead and useless.
|
||||
|
||||
# Sobriquets
|
||||
|
||||
- A dead program which sits there doing nothing is known as a 'zombie'.
|
||||
- A program which is run by another program is called a 'child program'.
|
||||
- A child whose parent program is dead is called an 'orphan'.
|
||||
- A child who remains running despite being useless because the parent is dead is called an 'orphan zombie'.
|
||||
|
||||
9
system/links.md
Normal file
9
system/links.md
Normal file
@@ -0,0 +1,9 @@
|
||||
---
|
||||
title: "links"
|
||||
tags: [ "basics", "links" ]
|
||||
---
|
||||
|
||||
There are two types:
|
||||
|
||||
- [Soft links](soft_links.md)
|
||||
- [Hard links](hard_links.md)
|
||||
55
system/locale.md
Normal file
55
system/locale.md
Normal file
@@ -0,0 +1,55 @@
|
||||
---
|
||||
title: "locale"
|
||||
tags: [ "basics", "time" ]
|
||||
---
|
||||
|
||||
Your locale tells the computer your location, preferred time-and-date format, standard language, papersize, et c.
|
||||
A list of supported locales is available at /usr/share/i18n/SUPPORTED
|
||||
|
||||
See a full list with:
|
||||
|
||||
```sh
|
||||
cat /usr/share/i18n/SUPPORTED
|
||||
```
|
||||
|
||||
Take the first portion to generate full locale information for a region:
|
||||
|
||||
```sh
|
||||
locale-gen ru_RU.UTF-8
|
||||
```
|
||||
|
||||
Then use this for the current shell session with
|
||||
|
||||
```sh
|
||||
LANG=ru_RU.utf8
|
||||
```
|
||||
|
||||
Expand this to the entire system with:
|
||||
|
||||
```sh
|
||||
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:
|
||||
|
||||
```sh
|
||||
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. |
|
||||
|
||||
92
system/processes.md
Normal file
92
system/processes.md
Normal file
@@ -0,0 +1,92 @@
|
||||
---
|
||||
title: "processes"
|
||||
tags: [ "basics" ]
|
||||
---
|
||||
# Proccesses
|
||||
|
||||
See running items in current terminal with
|
||||
|
||||
```sh
|
||||
ps
|
||||
```
|
||||
|
||||
or more with
|
||||
|
||||
```sh
|
||||
ps -a
|
||||
```
|
||||
|
||||
Or the entire system with
|
||||
|
||||
```sh
|
||||
ps -e
|
||||
```
|
||||
|
||||
Or the entire system with more information, BSD style, with:
|
||||
|
||||
```sh
|
||||
ps aux
|
||||
```
|
||||
|
||||
And then search for a particular program with
|
||||
|
||||
```sh
|
||||
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
|
||||
|
||||
```sh
|
||||
jobs
|
||||
```
|
||||
|
||||
And then you can pull number 1 up again with
|
||||
|
||||
```sh
|
||||
fg 1
|
||||
```
|
||||
|
||||
Or continue running a stopped job with:
|
||||
|
||||
```sh
|
||||
bg 1
|
||||
```
|
||||
|
||||
# Nice
|
||||
|
||||
This changes how nice a program is, from -20 to 19.
|
||||
|
||||
Install a program, but nicely, at nice value '10':
|
||||
|
||||
```sh
|
||||
nice -10 sudo apt -y install libreoffice
|
||||
```
|
||||
|
||||
Aggressively use Steam, with a nice value of '-13'.
|
||||
|
||||
```sh
|
||||
nice --13 steam&
|
||||
```
|
||||
|
||||
Find out that Steam's fucking everything up, so you change its nice value with 'renice':
|
||||
|
||||
```sh
|
||||
renice --5 -p 3781
|
||||
```
|
||||
|
||||
Nerf all of roach-1's processes:
|
||||
|
||||
```sh
|
||||
renice 10 -u roach-1
|
||||
```
|
||||
|
||||
... or the entire group
|
||||
|
||||
```sh
|
||||
renice -14 -g hackers
|
||||
```
|
||||
|
||||
72
system/soft_links.md
Normal file
72
system/soft_links.md
Normal file
@@ -0,0 +1,72 @@
|
||||
---
|
||||
title: "soft links"
|
||||
tags: [ "basics", "links" ]
|
||||
---
|
||||
A soft link is a file which says how to go to another file.
|
||||
When a program encounters a soft link, it will make a guess at whether it should ignore it, or try to get to that file.
|
||||
|
||||
To make a soft link to a file in the current directory, linking is easy:
|
||||
|
||||
```sh
|
||||
fortune > $file_1
|
||||
ln -s $file_1 $link_1
|
||||
```
|
||||
|
||||
Now imagine your directory looks like this:
|
||||
|
||||
```
|
||||
dir_0/
|
||||
├── dir_1
|
||||
│ └── file_1
|
||||
├── dir_2
|
||||
│ └── file_1
|
||||
├── file_1
|
||||
└── link_1
|
||||
|
||||
```
|
||||
|
||||
Inside `dir_1`, making a soft link to `dir_0/file_1` would mean putting the directions to that file:
|
||||
|
||||
```sh
|
||||
cd dir_1
|
||||
ln -s ../file_1 link_1
|
||||
```
|
||||
|
||||
The real content of the file is just '`../file_1`, so making it from another directory would mean writing exactly the same address to that file:
|
||||
|
||||
```sh
|
||||
ln -s ../file_1 dir_2/link_2
|
||||
```
|
||||
|
||||
Both symlinks are identical, except for the name.
|
||||
|
||||
```
|
||||
dir_0/
|
||||
├── dir_1
|
||||
│ ├── file_1
|
||||
│ └── link_1 <-- This one points to ../file_1
|
||||
├── dir_2
|
||||
│ ├── file_1
|
||||
│ └── link_2 <-- This one points to ../file_1 as well.
|
||||
└── file_2
|
||||
|
||||
```
|
||||
|
||||
Since it's just an address, you can delete the original file, then make another.
|
||||
|
||||
```sh
|
||||
rm file_1
|
||||
ls -l dir_1/
|
||||
fortune > file_1
|
||||
cat dir_2/link_2
|
||||
fortune | tee -a file_1
|
||||
cat dir_1/link_1
|
||||
```
|
||||
|
||||
Last, let's make a link from `dir_2/link_2` to `dir_1/file_1` (this will delete the old link):
|
||||
|
||||
```sh
|
||||
ln -s -f ../dir_1/file_1 dir_2/link_2
|
||||
cat dir_2/link_2
|
||||
```
|
||||
|
||||
268
system/users.md
Normal file
268
system/users.md
Normal file
@@ -0,0 +1,268 @@
|
||||
---
|
||||
title: "users"
|
||||
tags: [ "basics" ]
|
||||
---
|
||||
# Basic Information
|
||||
|
||||
Let's get some entries with 'getent', e.g. passwd or group.
|
||||
|
||||
```sh
|
||||
getent passwd
|
||||
```
|
||||
|
||||
```sh
|
||||
getent group
|
||||
```
|
||||
|
||||
Obviously:
|
||||
|
||||
```sh
|
||||
getent shadow
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
```sh
|
||||
sudo adduser maestro
|
||||
```
|
||||
|
||||
add user 'maestro'
|
||||
|
||||
This depends upon the settings in the /etc/default/useradd file and /etc/login.defs
|
||||
|
||||
```sh
|
||||
sudo useradd -m pinkie
|
||||
```
|
||||
|
||||
add user 'pinkie' with a home directory
|
||||
|
||||
```sh
|
||||
sudo adduser -m -e 2017-04-25 temp
|
||||
```
|
||||
|
||||
add expiry date to user
|
||||
|
||||
```sh
|
||||
userdel maestro
|
||||
```
|
||||
|
||||
delete maestro
|
||||
|
||||
```sh
|
||||
userdel -r maestro
|
||||
```
|
||||
|
||||
delete maestro and hir homefolder
|
||||
|
||||
```sh
|
||||
groups
|
||||
```
|
||||
|
||||
find which group you are in
|
||||
|
||||
|
||||
```sh
|
||||
id
|
||||
```
|
||||
|
||||
same
|
||||
|
||||
```sh
|
||||
id -Gn maestro
|
||||
```
|
||||
|
||||
Find which groups maestro is in
|
||||
|
||||
|
||||
```sh
|
||||
deluser --remove-home maestro
|
||||
```
|
||||
|
||||
delete user maestro
|
||||
|
||||
|
||||
```sh
|
||||
usermod -aG sudo maestro
|
||||
```
|
||||
|
||||
Add user maestro to group sudo:
|
||||
|
||||
|
||||
```sh
|
||||
cat /etc/passwd
|
||||
```
|
||||
|
||||
list users' passwords (and therefore users)
|
||||
|
||||
```sh
|
||||
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.
|
||||
|
||||
```sh
|
||||
passwd -l bin
|
||||
```
|
||||
|
||||
Lock the user 'bin'.
|
||||
|
||||
```sh
|
||||
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.
|
||||
|
||||
```sh
|
||||
groupdel learners | delete the group 'learners'
|
||||
```
|
||||
|
||||
```sh
|
||||
gpasswd -d pi games | remove user 'pi' from the group 'games'
|
||||
```
|
||||
|
||||
```sh
|
||||
id games
|
||||
```
|
||||
|
||||
find the id number of group 'games' (60)
|
||||
|
||||
```sh
|
||||
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:
|
||||
|
||||
```sh
|
||||
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:
|
||||
|
||||
```sh
|
||||
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:
|
||||
|
||||
```sh
|
||||
groupmod -n frontoffice backoffice
|
||||
```
|
||||
|
||||
Delte a group:
|
||||
|
||||
```sh
|
||||
groupdel frontoffice
|
||||
```
|
||||
|
||||
# Logins
|
||||
|
||||
See list of logged on users.
|
||||
|
||||
```sh
|
||||
w
|
||||
```
|
||||
|
||||
See last logons:
|
||||
|
||||
```sh
|
||||
last
|
||||
```
|
||||
|
||||
or all logon attempts, including bad attempts:
|
||||
|
||||
```sh
|
||||
lastb
|
||||
```
|
||||
|
||||
List recently accessed files:
|
||||
|
||||
```sh
|
||||
last -d
|
||||
```
|
||||
|
||||
See files opened by steve
|
||||
|
||||
```sh
|
||||
lsof -t -u steve
|
||||
```
|
||||
|
||||
See files opened by anyone but steve
|
||||
|
||||
```sh
|
||||
lsof -u ^steve
|
||||
```
|
||||
|
||||
# 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:
|
||||
|
||||
```sh
|
||||
sudo find / -type f -perm -g=s -ls
|
||||
```
|
||||
|
||||
And then those executable by the group:
|
||||
|
||||
```sh
|
||||
find / -type f -perm -g=s -ls
|
||||
```
|
||||
|
||||
And finally, worrying files, executable by anyone as if sie were the owner:
|
||||
|
||||
```sh
|
||||
find / -xdev \( -o -nogroup \) -print
|
||||
```
|
||||
|
||||
Then have a look at resource usage per user.
|
||||
|
||||
# SGID
|
||||
|
||||
```sh
|
||||
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.
|
||||
|
||||
Reference in New Issue
Block a user