• Uncategorized

    List all IP addresses connected to your Server

    Below is an Unix command to list all the IP addresses connected to your server on port 80. Output – Total connections by IP, from highest to lowest. Note This command is useful to detect if your server is under attack, and null route those IPs. Read this null route attacker IP story. Let break above lengthy command into pieces : 1. netstat -tn 2>/dev/null Uses netstat to list all network connections, ins and outs. -n – Display numeric only, don’t resolve into name. -t – Display only TCP connections. Output 2>/dev/null Redirect all unwanted output to /dev/null, a special place to absorb all output and clear it. 2. grep…

  • Uncategorized

    Know Your IP Using Command Line

    If you are not behind a router, you can find it out using ifconfig. If you are behind a router, then your computer will not know about the public IP address as the router does a network address translation. You could ask some website what your public IP address is using curl or wget and extract the information you need from it: or shorter

  • Uncategorized

    How to know if a disk is an SSD or an HDD

    Linux automatically detects SSD, and since kernel version 2.6.29, you may verify sda with: You should get 1 for hard disks and 0 for a SSD. It will probably not work if your disk is a logical device emulated by hardware (like a RAID controller). See this answer for more information… ************************************************ With lsblk (part of the util-linux package): lsblk -d -o name,rota where ROTA means rotational device (1 if true, 0 if false)

  • Uncategorized

    CHroot sftp-only SSH users into their homes

    To chroot an SFTP directory, you must : To chroot an SFTP directory, you must Create an user and force root to be owner of it cd /home mkdir john useradd -d /home/john -M -N -g users john sudo chown root:root /home/john sudo chmod 755 /home/john Change the subsystem location on /etc/ssh/sshd_config: #Subsystem sftp /usr/lib/openssh/sftp-server Subsystem sftp internal-sftp and create a user section at the end of the file (ssh can die respawning if placed after Subsystem line): Match User john ChrootDirectory /home/john ForceCommand internal-sftp AllowTCPForwarding no X11Forwarding no

  • Uncategorized

    How To Find Word(s) On Files in Linux

    Do the following: -r or -R is recursive, -n is line number, and -w stands for match the whole word. -l (lower-case L) can be added to just give the file name of matching files. Along with these, --exclude, --include, --exclude-dir flags could be used for efficient searching: This will only search through those files which have .c or .h extensions: grep --include=\*.{c,h} -rnw '/path/to/somewhere/' -e "pattern" This will exclude searching all the files ending with .o extension: grep --exclude=*.o -rnw '/path/to/somewhere/' -e "pattern" For directories it’s possible to exclude a particular directory(ies) through --exclude-dir parameter. For example, this will exclude the dirs dir1/, dir2/ and all of them matching…

  • Uncategorized

    How to Get Primary IP on Linux

    Use grep to filter IP address from ifconfig: ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1' Or with sed: ifconfig | sed -En 's/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p' If you are only interested in certain interfaces, wlan0, eth0, etc. then: ifconfig wlan0 | ... You can alias the command in your .bashrc to create your own command called myip for instance. alias myip="ifconfig | sed -En 's/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p'" A much simpler way is hostname -I (hostname -i for older versions of hostname but see comments). However, this is on Linux only.