Screen Shortcuts
New window: Ctrl-A
then c
Select window from list Ctrl-A
then "
Split vertically Ctrl-A
then S
Split horizontally Ctrl-A
then |
Move to next pane Ctrl-A
then <tab>
Move to previous pane Ctrl-A
then <shift> <tab>
Close current pane Ctrl-A
then X
Kill current window Ctrl-A
then k
Kill all windows Ctrl-A
then \
Detach from session Ctrl-A
then d
List sessions screen -ls
Reattach to session: screen -r
, or screen -r [ID]
if there is more than one seccion to pick from
Scroll: Ctrl-A
then Esc
. Use up
and down
to scroll
Connect to serial port screen /dev/ttyXXX 115200
Useful Linux Commands
Add a user to a group
sudo usermod -a -G <group> <user>
# E.g. Add user "james" to Virtual Box shared folder group
sudo usermod -a -G vboxsf james
# E.g. Add user "james" to serial group
sudo usermod -a -G dialout james
# E.g. Add current user to docker group
sudo usermod -a -G docker $USER
Make a random binary file
# Make 2048 byte random file
dd if=/dev/urandom of=file.bin bs=2048 count=1
Split and combine files
# Split a single file into multiple 1GB files
# Output files will be named split_file.bin.aa, split_file.bin.ab, etc
split -b 1G input_file.bin split_file.bin.
# Combine multiple files into one
cat split_file.bin.* > combined_file.bin
View logs of systemd services
# View logs
journalctl -u service.name
# View live updating logs
journalctl -f -u service.name
TAR commands
# Compress contents of directory of files
cd dir_name
# How to remember: Compress Zee Filez, Verbose me now
tar czfv ../archive.tar.gz .
# Extract the files into the current directory
# How to remember: eXtract Zee File, Verbose me now
tar xzfv archive.tar.gz ./
Allow port with iptables
Allow incomming connections to TCP port 8080 on interface eth0.
iptables -A INPUT -i eth0 -p tcp --dport 8080 -j ACCEPT
# Make persistent
netfilter-persistent save
GDB
Run program with command line arguments.
gdb program_name
run <command_line_arguments>
NFS
# Share a directory
vi /etc/exports
# Add read / write access from 10.0.4.X
/path/to/dir 10.0.4.0/24(rw,sync,no_root_squash)
# Restart NFS
sudo systemctl restart nfs
SSH
Enable access to server via SSH key.
# Create SSH key (RSA)
ssh-keygen -t rsa -b 4096
# Create SSH key (ED25519)
ssh-keygen -t ed25519
# Copy SSH key to remote server
ssh-copy-id -i ~/.ssh/key_file_name user@host
Disable SSH host key checking. Useful when connecting to embedded systems with initramfs, as the host key changes each time.
sudo vi ~/.ssh/config
Host 10.0.4.1
StrictHostKeyChecking no
UserKnownHostsFile=/dev/null
# Host file must be owned by root, and have no group / other write permissions
sudo chmod go-w ~/.ssh/config
Can use Host *
to disable on all hosts, but not typically a good idea.
Useful pip commands
Install from a .whl file
python -m pip install file.whl
Install from a git repository
# Repo is python package
pip install git+https://url_of_repo.git
# Repo contains python package in subdirectory
pip install git+https://url_of_repo.git#subdirectory=path/to/python/setup/file
Download package and dependencies
The following commands download a python package and all it's dependencies into the directory the command is run from.
# Downloads package for python version installed on the local machine
pip download <package_name>
# Download matplotlib for Python 2.7 on Windows
pip download matplotlib --only-binary=:all: --python-version 2.7 --platform win_amd64
# Download matplotlib for Python 3.9 on Linux
pip download matplotlib --only-binary=:all: --python-version 3.9 --platform manylinux1_x86_64
# Info about manylinux here: https://github.com/pypa/manylinux