which package a file belongs

get the path of binary

whereis ls

using dpkg

dpkg -S /bin/ls

using rpm

rpm -qf /usr/bin/ls
Advertisements

create a ssh alias

Add the lines below in .ssh/config file to create a new alias

vi .ssh/config

Host 7
  HostName 192.168.0.7
  User root

Connect using the alias

ssh 7

Generates configuration file entries for all IPs of a network

nmap -sP 192.168.0.0/24 | egrep -o '([0-9]{1,3}\.){3}[0-9]{1,3}' | sort -n -t . -k 4 | awk '{print "Host "substr( $1,13,3 )"\n  Hostname " $1"\n"}'

connect in screen session if you have one already open

1 – Create the file that will be inserted in the user’s .bashrc

vi /usr/local/bin/include_bashrc_users.sh

#!/bin/bash
# Connect in screen session if you have one open

SESSION_ID=$( screen -ls | grep -P '\t' | cut -d. -f1 | tr -d '\t' )
if [ -z $SESSION_ID ]; then
  text='Started new session with screen!'; printf "%*s\n" $(((${#text}+$COLUMNS)/2)) "$text"
  screen -R
else
  text='Connected in existing screen session!'; printf "%*s\n" $(((${#text}+$COLUMNS)/2)) "$text"
  screen -r $SESSION_ID
  date && pwd
fi

2 – add the above script in the end of .bashrc user’s file

vi ~/.bashrc

source /usr/local/bin/include_bashrc_users.sh

Limiting 1 login per user (optional step)

echo 'userNameHere hard maxlogins 1' >> /etc/security/limits.d/users.conf