by hyper_reality · 6y ago · 0 comments
Generate Random Passwords
>_ < /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c6
This produces a 6-character password which only has 35 bits of entropy. It also doesn't print a newline, causing the password to be on the same line as the next prompt. Better to use something like: >_ < /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c12 && echo
Or the "pwgen" utility which can do this for you. Find the process that is using a certain port e.g. port 3000
>_ lsof -P | grep ':30000'
This command will be extremely slow on large systems with a lot of open files. It is essentially listing every open file (the -P flag just inhibits port mappings from e.g. "port 22" to "SSH") and then grepping the output. Much better to run: >_ lsof -i :30000
Which is not only shorter, but much faster as it directly gets info about that port. Add your public SSH key to a server in one command
>_ cat .ssh/id_rsa.pub | ssh hostname 'cat >> .ssh/authorized_keys'
This is what the "ssh-copy-id" utility, which is part of the openssh-client package, does already. Harder, Faster, Stronger SSH clients
>_ ssh -4 -C -c blowfish-cbc
All three of those points are debatable with that command. Just use the defaults. head -c 33 /dev/urandom | base64
It has 264 bits of entropy.shuf -r -e --random-source=/dev/urandom {a..z} {0..9} {A..Z} | paste -d "" -s | fold -w 25
For finding a process on a port, use ss
ss -pn| grep :22
for a listening process ss -lpn |grep :22Find biggest 10 files in current and subdirectories and sort by file size
>_ find . -type f -print0 | xargs -0 du -h | sort -hr | head -10
alternative,
>find ./ -printf '%s--%p\n'| sort -nr | head
You and some other commenters have a great knowledge. Can't wait to dig into it and add it to the page! Thanks a lot
alternative
>_ find . -empty -type d -delete
GNU find says this very specifically: "There are unavoidable security problems surrounding the -exec action..."
Simple xargs builds the longest possible command line with as many find results as can fit.
If the -n option were used with xargs, it might slow down to similar performance as -exec, but it would still be safer.
Multiple processes can also be launched by the xargs, increasing performance by using multiple CPUs.
Here is a script using xargs -0 to launch 6 compression processes at a time on files specified to a shell script:
#!/bin/sh
N_CPUs=6
EXT="xz"
S="$(mktemp -t PARALLEL-XXXXXX)"
printf '#!/bin/sh \n exec xz -9e "$1"' > "$S"
chmod 500 "$S"
if [[ -z "$1" ]]
then echo "Specify files to pack into ${EXT} files."
else for x
do printf '%s\0' "$x"
done | xargs -0 -P "$N_CPUs" -Ifname "$S" fname
fi
rm -f "$S"