black electronics

Linux Tips & Tricks

General Linux tips for sudo access, text cleanup, shared folders and file transfers.

A grab-bag of general Linux tips that don’t belong to any one tool, but come up often enough during engagements to be worth keeping in one place.

Check sudo access

Terminal window
cat /etc/group | grep sudo # List members of the sudo group
sudo cat /etc/sudoers # Review sudo rules (requires sudo access)
usermod -a -G sudo username # Add a user to the sudo group

To let a user run a specific command without a password prompt, add a line like this to /etc/sudoers (via visudo):

username ALL=NOPASSWD: /etc/init.d/ssh

Run a shell as another user (as root)

Terminal window
su -c bash username

Show all completions on TAB instead of cycling through them

Terminal window
sudo nano /etc/inputrc
set completion-query-items 1000 # 0 = no limit

Mount a VMware shared folder in a Linux guest

Terminal window
cd /mnt/hgfs/
ls

If /mnt/hgfs/ doesn’t exist yet:

Terminal window
sudo mkdir -p /mnt/hgfs
sudo vmhgfs-fuse .host:/SharedFolder /mnt/hgfs -o allow_other # Change "SharedFolder" to the name set in VMware

Clean up extracted text

Terminal window
sudo sed -i -E 's|https?://||g' *.txt # Strip http:// and https:// from every line in every .txt file
Terminal window
# Count total characters across a text file
awk 'BEGIN{FS=""}{for(i=1;i<=NF;i++)c++}END{print "total chars:"c}' wordlist.txt
Terminal window
# Total line count across every .txt file in a folder
wc -l *.txt | awk '{total += $1} END {print total}'

Convert a colon-delimited combo list to CSV

Terminal window
{
echo '"URL","Username","Password"'
awk -F: '
NF==3 {
gsub(/\r/, "", $1); gsub(/\r/, "", $2); gsub(/\r/, "", $3);
gsub(/"/, "\"\"", $1); gsub(/"/, "\"\"", $2); gsub(/"/, "\"\"", $3);
printf "\"%s\",\"%s\",\"%s\"\n", $1, $2, $3
}
' combolist.txt
} > output.csv

Secure copy over SSH

Terminal window
scp *.txt user@remote_host:/path/to/destination/
Useful LinksPentest PayloadsCheat Sheets