Merge branch 'dev' into vhs

This commit is contained in:
2023-06-20 15:08:40 +02:00
105 changed files with 2494 additions and 3310 deletions

View File

@@ -4,29 +4,45 @@ tags: [ "Documentation", "Basics" ]
---
Install with:
> sudo apt install at
```bash
sudo apt install at
```
Enable the daemon service with:
> sudo systemctl enable --now atd
```bash
sudo systemctl enable --now atd
```
Then jobs can be specified with absolute time, such as:
> at 16:20
```bash
at 16:20
```
> at noon
```bash
at noon
```
> at midnight
```bash
at midnight
```
> at teatime
```bash
at teatime
```
Type in your command, e.g.:
> touch /tmp/myFile.txt
```bash
touch /tmp/$FILE.txt
```
The jobs can also be specified relative to the current time:
> at now +15 minutes
```bash
at now +15 minutes
```
Finally, accept the jobs with ^D.
@@ -34,15 +50,19 @@ Finally, accept the jobs with ^D.
Display a list of commands to run with:
> atq
```bash
atq
```
`2 Sat Oct 20 16:00:00 2018 a roach-1`
> 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
```bash
atrm 2
```
Check /var/spool/atd/
Check `/var/spool/atd/` to see the jobs.
![At it again](/tapes/at.gif)
@@ -50,10 +70,10 @@ Check /var/spool/atd/
Automatically add a job for later, by setting the date, then using echo for the command.
> t="$(date -d "2 minutes" +%R)"
> echo "fortune > ~/file" | at "$t"
> watch cat file
```bash
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)"`.

View File

@@ -9,91 +9,136 @@ Don't worry about understanding any of it, just type it in and the habit forms p
You start in a dark room. You want to know where you are by **p**rinting out your **w**orking '**d**irectory' (i.e. 'location'):
> pwd
```bash
pwd
```
Have a look at what is here:
> ls
```bash
ls
```
If you get no response, the list of items is "", meaning "nothing here".
Have a look at **a**ll the files:
> ls -a
```bash
ls -a
```
`. ..`
```bash
. ..
```
So `.` means 'here' and `..` means 'you see stairs leading downwards' (e.g. 'the directory behind you').
Change directory (`cd`) down one level:
> cd ..
```bash
cd ..
```
Look where you are again with `pwd`, then go back up. Use `ls`, and if you see `bob`, then:
> cd bob
```bash
cd bob
```
Move around the directories. The place at the bottom is the 'root', and is known as `/`. Go to the root:
> cd /
```bash
cd /
```
Do `ls` again and change into `etc`. Look at how much space those folders are taking up:
Do `ls` again and `cd` into `etc`. Look at how much space those folders are taking up:
> du iptables
```bash
du iptables
```
That's the number of kilobytes the file is taking up.
Do the same again, but in a human-readable format:
That's the number of kilobytes the file is taking up. Do the same again, but in a human-readable format:
```bash
du -h iptables
```
> 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:
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
```bash
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
```bash
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:
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
```bash
exit
```
Go find a file that isn't a directory. You can tell which is which with:
> ls -l
```bash
ls -l
```
A directory starts with a 'd', like this:
`drwxr-xr-x 79 root root 4096 Jan 3 05:15 /etc/`
```bash
drwxr-xr-x 79 root root 4096 Jan 3 05:15 /etc/
```
A standard file starts with '-', like this:
```bash
`-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
```bash
cat /etc/hostname
```
Print out the words "hello world":
> echo "hello world"
```bash
echo "hello world"
```
Move back to your home directory:
> cd
```bash
cd
```
Take the words 'hello world', and put them in 'my_file':
> echo 'hello world' > my_file
```bash
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
```bash
du $FILE >> $FILE
```
And check the results:
> cat my_file
```bash
cat $FILE
```
# Autocompletion
@@ -103,50 +148,70 @@ Press tab after typing a few keys and bash will guess what you're trying to typ
Look at your file's owner:
> ls -l my_file
```bash
ls -l $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
```bash
sudo chown root $FILE
```
Change the same file so it's owned by the group 'audio':
> sudo chown :audio my_file
```bash
sudo chown :audio $FILE
```
Check you did that correctly:
> ls -l my_file
```bash
ls -l my_file
```
`-rw-r--r-- 1 root audio 0 Jan 3 19:20 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
```bash
rm $FILE
```
You'll see you're not allowed, because you don't own it.
Look at which groups you're in:
> groups
```bash
groups
```
Change the file so that members of the audio group can write to the file:
> sudo chmod g+w my_file
```bash
sudo chmod g+w $FILE
```
Check you got it right with `ls -l`:
> -rw-rw-r-- 1 root audio 0 Jan 3 19:20 my_file
```bash
-rw-rw-r-- 1 root audio 0 Jan 3 19:20 my_file
```
Try to delete the file again:
> rm my_file
```bash
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 ]
```bash
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.
@@ -154,59 +219,83 @@ Now you should be able to remove (delete) the file. Remember, that using 'rm fi
Make a directory called 'new test':
> mkdir 'new test'
```bash
mkdir 'new test'
```
Make two directories, called 'A', and 'Z':
> mkdir A Z
```bash
mkdir A Z
```
Make a single directory called 'A Z'
> mkdir 'A Z'
```bash
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
```bash
du -sch * > A/'disk usage'.txt
```
Look at your file:
> cat A/'disk usage.txt'
```bash
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
```bash
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
```bash
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
```bash
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
```bash
rmdir Z
```
Remove the directory 'Z':
> rmdir Z
```bash
rmdir Z
```
And then remove all the rest:
> rmdir *
```bash
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
```bash
rm -r A
```
# Installation
@@ -214,34 +303,48 @@ 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
```bash
whereis yum
```
> whereis apt
```bash
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
```bash
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
```bash
sudo apt install lolcat
```
Try the same command again.
Search for things you want, like `libreoffice`, or `gimp`:
> apt search libreoffice
```bash
apt search libreoffice
```
... then install one of them with:
> apt install [ thing ]
```bash
apt install $PROGRAM
```
Remove `lolcat`, because it's useless:
> sudo apt remove lolcat
```bash
sudo apt remove lolcat
```
... and that's pretty much it. You can move, create, destroy, install things, and look things up.

View File

@@ -5,27 +5,39 @@ tags: [ "Documentation", "Basics" ]
Show system time:
> date
```bash
date
```
Show hardware time:
> sudo hwclock -r
```bash
sudo hwclock -r
```
Change system time to match hardware time:
> sudo hwclock --hctosys
```bash
sudo hwclock --hctosys
```
Change hardware time to match system time:
> sudo hwclock --systohc
```bash
sudo hwclock --systohc
```
Manually set the hardware time to a specified date:
> sudo hwclock --set --date="8/25/19 13:30:00"
```bash
sudo hwclock --set --date="8/25/19 13:30:00"
```
## Normal Date
> date +%d/%m/%y
```bash
date +%d/%m/%y
```
# Unix Time
@@ -33,7 +45,9 @@ Computers started counting time on January 1st, 1970, and added one second-per-s
Track the time in Unix-time:
> date +%s
```bash
date +%s
```
# Network Time Providers
@@ -41,9 +55,13 @@ Servers which take their time from an observatory we call Stratum 1 servers. Se
Install ntp with:
> sudo apt-get install -y ntp
```bash
sudo apt-get install -y ntp
```
The shell command for this is `ntpq`. Monitor the service providers using:
> ntpq -p
```bash
ntpq -p
```

View File

@@ -41,29 +41,28 @@ case $CRE in
owlbears | monsters ) echo "Really you're a wizard fan"
;;
esac
```
# While and Until
This prints from 1 until 9.
> COUNTER=1
> while [ $COUNTER -lt 2 ]; do
```bash
COUNTER=1
while [ $COUNTER -lt 2 ]; do
> ((COUNTER++))
> echo $COUNTER
> done
```
There's also 'until', which stops when something is true, rather than keeping going when something is true.
# For
> for i in $( ls ); do
```bash
for i in $( ls ); do
> du -sh $i
> done
```
# Sequences
@@ -71,13 +70,19 @@ The sequences tool counts up from X in jumps of Y to number Z.
Count from 1 to 10.
> seq 10
```bash
seq 10
```
Count from 4 to 11.
> seq 4 11
```bash
seq 4 11
```
Count from 1 to 100 in steps of 5.
> seq 1 5 100
```bash
seq 1 5 100
```

View File

@@ -6,24 +6,29 @@ tags: [ "Documentation", "Basics" ]
The crontab program might have various names, like `cronie` or `crond`.
> sudo apt search -n ^cron
```bash
sudo apt search -n ^cron
```
Once installed, search for the service name, and start it.
> sudo systemctl list-unit-files | grep cron
```bash
sudo systemctl list-unit-files | grep cron
```
> sudo systemctl enable --now cron
```bash
sudo systemctl enable --now cron
```
You can *e*dit your crontab with:
> crontab -e
```bash
crontab -e
```
39 */3 * * * /usr/bin/updatedb
```
> 39 */3 * * * /usr/bin/updatedb
## Syntax
`* * * * *`
@@ -34,29 +39,33 @@ These five points refer to:
So '3pm every Sunday' would be:
`0 15 * * 7`
> 0 15 * * 7
Here 'Sunday' is indicated by "7", and '3pm' is 'the 15th hour'.
The minute is '0' (i.e. '0 minutes past three pm').
Doing the same thing, but only in February, would be:
`0 15 * 2 7`
> 0 15 * 2 7
### Full Paths
Executing something requires the full path to where it is, so you cannot simply use `apt update -y`, because cron does not know where `apt` is.
Instead, find out where it is:
> type -P apt
```bash
type -P apt
```
`/usr/bin/apt`
Then put that into the crontab:
> sudo crontab -e
```bash
sudo crontab -e
```
`40 */3 * * * /usr/bin/apt update -y`
> 40 */3 * * * /usr/bin/apt update -y
This will run `apt update -y` as root every 3 hours, at 40 minutes past the hour, e.g. 00:40, 03:40, 06:40.
@@ -65,13 +74,17 @@ This will run `apt update -y` as root every 3 hours, at 40 minutes past the hour
You can execute a script as root by putting it into a directory, instead of in the tab.
Look at the available cron directories:
> ls /etc/cron.\*
```bash
ls /etc/cron.\*
```
### Testing with runparts
Run-parts runs all executable scripts in a directory.
> run-parts /etc/cron.hourly
```bash
run-parts /etc/cron.hourly
```
## Tips
@@ -84,12 +97,16 @@ First add `HOME=/home/user`, then you can use syntax like this:
*Remember to test the script by executing that line first*:
> $HOME/.scripts/myScript.sh
```bash
$HOME/.scripts/myScript.sh
```
You can also add your regular path to your crontab as a variable (see example below).
If you're using vim as the editor, just run this at the top of your crontab:
> :r!echo PATH=$PATH
```bash
:r!echo PATH=$PATH
```
### `date` Commands

View File

@@ -10,17 +10,25 @@ Kernel modules live in lib/modules/$(uname -r)
Load them with
> sudo modprobe ath9k
```bash
sudo modprobe ath9k
```
Or remove one with
> sudo modprove uvcvideo
```bash
sudo modprove uvcvideo
```
The PC's irritating speaker beep can be really annoying. Disable it with:
> sudo modprobe -r pcspeaker
```bash
sudo modprobe -r pcspeaker
```
Permanently disable a module by blacklisting it in `/etc/modprobe.d`:
> echo 'blacklist pcspkr' > /etc/modprobe.d/*nobeep*.conf
```bash
echo 'blacklist pcspkr' > /etc/modprobe.d/*nobeep*.conf
```

View File

@@ -7,7 +7,9 @@ If you want to kill a program in a graphical environment, open a terminal and ty
# Graphical Programs
> xkill
```bash
xkill
```
Then click on the application which you want to kill.
@@ -15,23 +17,31 @@ Then click on the application which you want to kill.
To kill a program, find it with:
> pgrep discord
```bash
pgrep discord
```
This will give you the UUID, e.g. `19643`.
Kill the program with:
> kill 19643
```bash
kill 19643
```
# Types of Kill
To see an ordered list of termination signals:
> kill -l
```bash
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
> 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'.
@@ -39,18 +49,24 @@ Higher numbers are roughly equivalent to insistence.
For example:
> kill -1 3498
```bash
kill -1 3498
```
This roughly means 'maybe stop the program, if you can, maybe reload'.
Or the famous:
> kill -9 3298
```bash
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'.

View File

@@ -4,12 +4,16 @@ tags: [ "Documentation", "Basics" ]
---
Link from X to Y.
> ln -s X ../otherdir/Y
```bash
ln -s X ../otherdir/Y
```
If you want a hard link, this will make a single file exist in two locations.
If it is deleted in one location, it continues to exist in the other.
> ln *X* *Y*
```bash
ln *X* *Y*
```
Both files must be on the same hard drive, as they have the same inode (check this with `ls -i file`).

View File

@@ -3,29 +3,40 @@ title: "locale"
tags: [ "Documentation", "Basics" ]
---
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:
> cat /usr/share/i18n/SUPPORTED
```bash
cat /usr/share/i18n/SUPPORTED
```
Take the first portion to generate full locale information for a region:
> locale-gen ru_RU.UTF-8
```bash
locale-gen ru_RU.UTF-8
```
Then use this for the current shell session with
> LANG=ru_RU.utf8
```bash
LANG=ru_RU.utf8
```
Expand this to the entire system with:
> export LANG=ru_RU.utf8
```bash
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
```bash
sudo vim /etc/defaults/locale
```
# Variables

View File

@@ -6,7 +6,9 @@ tags: [ "Documentation", "Basics" ]
`type` shows what kind of thing you're running, be it an alias, function, or binary program.
> type cmus
```bash
type cmus
```
![where is cmus?](/tapes/which.gif)
@@ -18,18 +20,24 @@ Ask where the `angband` program is, along with all its configuration files:
Also `which` shows where a binary file (the program) is,
> which cmus
```bash
which 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
```bash
sudo updatedb
```
Then to find a file called 'my-cats.jpg', run:
> locate cats
```bash
locate cats
```
For best results, run `updatedb` regularly, perhaps in crontab.

View File

@@ -6,23 +6,33 @@ tags: [ "Documentation", "Basics" ]
See running items in current terminal with
> ps
```bash
ps
```
or more with
> ps -a
```bash
ps -a
```
Or the entire system with
> ps -e
```bash
ps -e
```
Or the entire system with more information, BSD style, with:
> ps aux
```bash
ps aux
```
And then search for a particular program with
> ps aux | grep cmus
```bash
ps aux | grep cmus
```
# Jobs
@@ -30,15 +40,21 @@ Pause a job with ^z. Put it in the background with the '&' suffix.
List jobs in the current shell with
> jobs
```bash
jobs
```
And then you can pull number 1 up again with
> fg 1
```bash
fg 1
```
Or continue running a stopped job with:
> bg 1
```bash
bg 1
```
# Nice
@@ -46,21 +62,31 @@ 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
```bash
nice -10 sudo apt -y install libreoffice
```
Aggressively use Steam, with a nice value of '-13'.
> nice --13 steam&
```bash
nice --13 steam&
```
Find out that Steam's fucking everything up, so you change its nice value with 'renice':
> renice --5 -p 3781
```bash
renice --5 -p 3781
```
Nerf all of roach-1's processes:
> renice 10 -u roach-1
```bash
renice 10 -u roach-1
```
... or the entire group
> renice -14 -g hackers
```bash
renice -14 -g hackers
```

View File

@@ -6,7 +6,9 @@ tags: [ "Documentation", "Basics" ]
Set time to synchronize with an ntp server:
> timedatectl set-ntp true
```bash
timedatectl set-ntp true
```
This info stays in `/usr/share/zoneinfo`.
@@ -16,7 +18,9 @@ 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
```bash
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.
@@ -24,23 +28,33 @@ According to Dave's LPIC guide, you can set the local time by making asymboling
See local time, language and character settings with:
> locale
```bash
locale
```
List available locales with:
> locale -a
```bash
locale -a
```
To see additional locales which are available (but not necessarily installed):
> cat /usr/share/i18n/SUPPORTED
```bash
cat /usr/share/i18n/SUPPORTED
```
Set a supported locale with:
> locale-gen pl_PL.UTF-8
```bash
locale-gen pl_PL.UTF-8
```
Then set that language, with:
> LANG=pl_PL.UTF-8
```bash
LANG=pl_PL.UTF-8
```
... then reboot.
@@ -48,7 +62,9 @@ Then set that language, with:
Glimpse an overview with:
> ntpq -p
```bash
ntpq -p
```
Usually this is run as a service, so just start that service.

View File

@@ -6,91 +6,133 @@ tags: [ "Documentation", "Basics" ]
Let's get some entries with 'getent', e.g. passwd or group.
> getent passwd
```bash
getent passwd
```
> getent group
```bash
getent group
```
Obviously:
> getent shadow
```bash
getent shadow
```
## Examples
> sudo adduser maestro
```bash
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
```bash
sudo useradd -m pinkie
```
add user 'pinkie' with a home directory
> sudo adduser -m -e 2017-04-25 temp
```bash
sudo adduser -m -e 2017-04-25 temp
```
add expiry date to user
> userdel maestro
```bash
userdel maestro
```
delete maestro
> userdel -r maestro
```bash
userdel -r maestro
```
delete maestro and hir homefolder
> groups
```bash
groups
```
find which group you are in
> id
```bash
id
```
same
> id -Gn maestro
```bash
id -Gn maestro
```
Find which groups maestro is in
> deluser --remove-home maestro
```bash
deluser --remove-home maestro
```
delete user maestro
> usermod -aG sudo maestro
```bash
usermod -aG sudo maestro
```
add user maestro to group sudo
Add user maestro to group sudo:
> cat /etc/passwd
```bash
cat /etc/passwd
```
list users' passwords (and therefore users)
> groupadd awesome
```bash
groupadd awesome
```
create the group 'awesome'
passwords are stored in /etc/shadow.
Passwords are stored in /etc/shadow.
there are user accounts for processes such as 'bin' and 'nobody' which are locked, so they're unusable.
There are user accounts for processes such as 'bin' and 'nobody' which are locked, so they're unusable.
> passwd -l bin
```bash
passwd -l bin
```
lock the user 'bin'
Lock the user 'bin'.
> more /etc/passwd | grep games
```bash
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'
```bash
groupdel learners | delete the group 'learners'
```
> gpasswd -d pi games | remove user 'pi' from the group 'games'
```bash
gpasswd -d pi games | remove user 'pi' from the group 'games'
```
> id games
```bash
id games
```
find the id number of group 'games' (60)
> usermod -aG sudo maestro
```bash
usermod -aG sudo maestro
```
add user to group 'maestro'
@@ -114,7 +156,9 @@ Alternatively, change the shell in /etc/passwd.
Usermod also lets you change a user's username:
> usermod -l henry mark
```bash
usermod -l henry mark
```
However, this will not change the home directory.
@@ -126,7 +170,9 @@ usermod -L henry
-G or -groups adds the user to other groups:
> usermod -G sudo henry
```bash
usermod -G sudo henry
```
-s adds the user to a shell.
@@ -140,45 +186,53 @@ In /etc/group, a group file may look like this:
We can use groupmod, like like usermod, e.g. to change a name:
> groupmod -n frontoffice backoffice
```bash
groupmod -n frontoffice backoffice
```
Delte a group:
> groupdel frontoffice
```bash
groupdel frontoffice
```
# Logins
See list of logged on users.
> w
```bash
w
```
See last logons:
> last
```bash
last
```
or all logon attempts, including bad attempts:
> lastb
```bash
lastb
```
List recently accessed files:
> last -d
```bash
last -d
```
See files opened by steve
> lsof -t -u steve
```bash
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
```bash
lsof -u ^steve
```
# Looking for Dodgy Files
@@ -186,21 +240,29 @@ Some files can be executed by people as if they had super user permissions, and
Let's start with files executable by user:
> sudo find / -type f -perm -g=s -ls
```bash
sudo find / -type f -perm -g=s -ls
```
And then those executable by the group:
> find / -type f -perm -g=s -ls
```bash
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
```bash
find / -xdev \( -o -nogroup \) -print
```
Then have a look at resource usage per user.
#SGID
# SGID
> sudo chmod u+s process.sh
```bash
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.