Friedrich Ewald My Personal Website

Posts


  • Show open ports on the linux shell

    If you want to show all the currently open ports on linux, just use the following command:

    netstat -lntu
    
    This gives you the following output:
    Active Internet connections (only servers)
    Proto Recv-Q Send-Q Local Address           Foreign Address         State
    tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN
    tcp        0      0 0.0.0.0:3128            0.0.0.0:*               LISTEN
    tcp6       0      0 :::22                   :::*                    LISTEN
    udp        0      0 0.0.0.0:39790           0.0.0.0:*
    udp        0      0 0.0.0.0:68              0.0.0.0:*
    udp        0      0 0.0.0.0:41121           0.0.0.0:*
    udp6       0      0 :::57063                :::*
    udp6       0      0 :::42147                :::*
    
    Found here

  • Using git efficiently on the console

    I was looking for ways to visualize the progress of a project and also I wanted to do this with on-board tools. After a quick search I found the following command.

    git log --graph --decorate --oneline
    
    This gives a nice and colorful overview when what branch was touched and how it was merged. To display the results in a nicer way, a alias in the ~/.giconfig helps:
    [alias]
    lg = !"git lg1"
    lg1 = !"git lg1-specific --all"
    lg2 = !"git lg2-specific --all"
    lg3 = !"git lg3-specific --all"
    
    lg1-specific = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)'
    lg2-specific = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n''          %C(white)%s%C(reset) %C(dim white)- %an%C(reset)'
    lg3-specific = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%
    
    The last speed trick is, to set an alias in the ~/.bashrc. This saves 2/3 of the letters.
    alias g='git'
    

  • Combining multiple CSV files to one

    If you have multiple CSV files with the same format and you want to combine them to just a single file, just do

    cat file1.csv file2.csv > output.csv
    
    Or even simpler
    cat *.csv > output.csv
    

  • Counting lines of a text file

    To count lines of one or many files on the shell I use wc (Wordcount). If you want to count all lines of all CSV files in a dictionary, just type:

    wc -l *.csv
    

  • Improving security for SSH

    There are two things to increase the security for ssh logins.

    Change SSH Port

    To change the SSH port, simply edit the sshd_config file with the commmand sudo nano /etc/ssh/sshd_config and change the line Port 22 to something higher. Make sure to stay below 65,000 and don’t use any port which is already used by another service like 80 (web). After changing and saving the file, simply restart the ssh daemon and reload the configuration with sudo /etc/init.d/ssh reload. Done.

    Disable password based login for SSH

    To disable the password based login for all the users, you can do the following:
    # Open the sshd config file
    sudo nano /etc/ssh/sshd_config
    
    Disable password authentication with the following settings:
    ChallengeResponseAuthentication no
    
    Allow private public key authentication with the following:
    RSAAuthentication yes
    PubkeyAuthentication yes
    
    Once this is done, restart the SSH daemon to apply the settings.
    /etc/init.d/sshd restart
    
    Additional information can be found here.

Page: 25 of 27