List of freqently used but never remembered commands
Mount CDROM
mount -r -t iso9660 /dev/sr0 /media
Curl stuff
curl http://<URL>/folder/file.txt --output file.txt
curl http://<URL>/folder/file.txt -o file.txt
Install from local CentOS media repo if no internet
mkdir /media/CentOS
mount -t iso9660 /dev/cdrom /media/CentOS
Check repo names in brackets [] in the media repo file
cat /etc/yum.repos.d/CentOS-Media.repo
Install from local repo
yum disablerepo=\* --enablerepo=c8-media-BaseOS --enablerepo=c8-media-AppStream install open-vm-tools
List Open Files and Ports
lsof -i -P -n | grep <PORT NUMBER>
Reference:
sudo fdisk -l
sudo fdisk /dev/sdb
- Press
n
to create a partition - Press
p
orl
to create primary or logical partitions - Press
w
to write your changes orq
to quit
sudo mkfs -t ext4 /dev/sdb1
sudo mkfs -t ext4 -N 2000000 /dev/sdb1
- This will manually set the number of inodes to 2,000,000
mount
- Shows what is mountedmkdir /mnt/mydrive
mount -t ext4 /dev/sdb1 /mnt/mydrive
ls -al /dev/disk/by-uuid/
or
blkid
Add the following line to your /etc/fstab
file adjusting the UUID to your device's id and the directory to where you want to mount:
UUID=811d3de0-ca6b-4b61-9445-af2e306d9999 /mnt/mydrive ext4 defaults 0 0
mount -a
- remounts filesystems from /etc/fstab
- Setup Github ssh keys
ssh-keygen -t rsa -b 4096 -C "EMAIL Address"
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa
ssh -T [email protected]
- Add keys to account
- Push SSH keys to another host if required
scp -r .ssh/ <NAME>@<HOST>:~
- Install Git if required
sudo yum -y install git
- Git config
git config --global color.ui auto
git config --global user.email "<NAME>@users.noreply.github.com"
git config --global user.name "<NAME>"
Run Git pull over subdirectories
for i in */.git; do ( echo $i; cd $i/..; git pull; ); done
ansible <HOST> -m ping
ansible <HOST> -a "/bin/echo hello"
ansible-playbook <playbook>.yml --tags <TAG NAME>
ansible <hostname> -m ansible.builtin.setup
Create a repo in Github without readme etc e.g. below using test-role
ansible-galaxy init --init-path . test-role
cd test-role
git init
git add .
git commit
git remote add origin [email protected]:nicholasrodriguez/test-role.git
git branch -M main
git push -u origin main
Goto [https://galaxy.ansible.com] and import
set shiftwidth=2
set expandtab
set tabstop=4
color desert
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
Configure
aws configure
sudo dnf install -y yum-utils
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
sudo dnf -y install docker-ce docker-ce-cli containerd.io
sudo systemctl enable --now docker
Manage Docker as a non-root user
sudo usermod -aG docker $USER
newgrp docker
Test Docker
docker info
docker run hello-world
Install Docker Compose
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
Test docker-compose
docker-compose --version
Download cert
mkdir -pv ~/.docker
unzip cert.zip -d ~/.docker
Set env var for remote host
export DOCKER_HOST=tcp://<docker host>:<port> DOCKER_TLS_VERIFY=1
Or create context and connect remotely
docker context create \
--docker host=ssh://[email protected] \
--description="Remote engine" \
my-remote-engine
Switch context
docker context use my-remote-engine
Create container interactively
sudo docker run -i -t centos:8 bash
Install stuff then exit
docker ps -a
docker commit <CONTAINER ID> infra-tools
Run another one
sudo docker run -i -t infra-tools bash
Connect to a stopped container
docker start -ia <CONTAINER ID>
Connect to a running container
docker exec -it <container name> /bin/bash
Mount local filesystem to a container
docker run -it -v $(pwd)/:/mnt/ mcr.microsoft.com/azurestack/powershell
Export to a file
docker save -o infra-tools.tar infra-tools:latest
Stop all containers
docker container stop $(docker container ls -aq)
Remove all containers
docker container rm $(docker container ls -aq)
https://docs.rockylinux.org/guides/migrate2rocky/
Got some odd package clashes on my personal CentOS 8 instances
sudo yum -y remove docker-ce
sudo yum -y remove docker-ce-cli
sudo yum -y remove containers-common
sudo yum -y remove containerd.io
sudo yum -y remove rpm-build
cd ~
git clone https://github.com/rocky-linux/rocky-tools.git
cd rocky-tools/migrate2rocky
chmod u+x migrate2rocky.sh
cd ~/rocky-tools/migrate2rocky
sudo ./migrate2rocky.sh -r
Plop the executable in
C:\Users\<USER NAME>\AppData\Local\Microsoft\WindowsApps