Skip to content

Instantly share code, notes, and snippets.

@npodonnell
Last active March 14, 2022 07:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save npodonnell/4468d2405d07238e0f8af2bf183ecde3 to your computer and use it in GitHub Desktop.
Save npodonnell/4468d2405d07238e0f8af2bf183ecde3 to your computer and use it in GitHub Desktop.
Random Commands

Random Commands

And Stuff ... mostly for Ubuntu/Debian

N. P. O'Donnell, 2021

Disable tap-to-click

synclient MaxTapTime=0

Prevent laptop from going to sleep when lid is closed

sudo sed -i "s/#\?HandleLidSwitch=.*/HandleLidSwitch=ignore/" /etc/systemd/logind.conf
sudo sed -i "s/#\?LidSwitchIgnoreInhibited=.*/LidSwitchIgnoreInhibited=no/" /etc/systemd/logind.conf

Netcat 1-line server

while true; do echo "hello" | nc -l 5000; done

Check which processes are listening on which TCP ports

lsof -nP -iTCP -sTCP:LISTEN

Find log files (or any files) between 2 timestamps

find ./*.log -type f -newermt "2021-04-30 00:00:00" ! -newermt "2021-05-02 00:00:00"

Perform sudo without password

sudo visudo

Perform the following change:

- %sudo   ALL=(ALL:ALL) ALL
+ %sudo   ALL=(ALL:ALL) NOPASSWD:ALL

Retain environment variables across sudo

For example you may want to keep the SSH_AUTH_SOCK variable so SSH agent keeps working:

sudo visudo

# Add variables like so:
Defaults    env_keep+=SSH_AUTH_SOCK

Formatting a USB Drive

Find out the device (sdb, sdb,... etc):

lsblk

Inspect the output. Run the above command again. Observe which device disappeared. Plug it in again, run command again, check that it re-appeared. Ensure you choose the correct device and not your OS drive or any other drive. Let's pretend the USB drive is device /dev/sdz.

Unmount:

sudo umount /dev/sdz

Wipe the drive and replace with random bytes:

sudo dd if=/dev/urandom of=/dev/sdz bs=1M status=progress

(Do this several times if you're paranoid)

Format with ext3:

sudo mkfs.ext3 /dev/sdz

Socat Relay

Forward TCP traffic on port 443 to example.com:

sudo socat TCP-LISTEN:443,reuseaddr,fork TCP-CONNECT:example.com:443

GNU Screen

List screen sessions:

screen -ls

Attaching

When one screen session exists:

screen -r

When multiple sessions exist:

screen -r <session ID>

Detaching

To detach from a screen session, if the session has a shell you can type into:

screen -d

If the session does not have a shell, press Ctrl-a, then press d. DO NOT press Ctrl-d. This will kill the session!

Killing

To kill a session from inside it, hit Ctrl-d.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment