Linux and Unix tips and tricks

Outline

The bash shell

Filesystems

Users and groups

Filesystem layout

Files

Environment variables

Shell paths

Processes

Pipes

Useful shell programs

Shell scripts

Shell scripting

Shell aliases and functions

Process control

bash history

Readline library (bash hotkeys)

More: http://www.catonmat.net/download/readline-emacs-editing-mode-cheat-sheet.pdf

Shell configuration

NBE computers

Installing programs

Tour of NBE filesystems

Quotas and permission problems

Triton

Batch queuing systems

Other useful programs

ssh

Standard arguments

Configuration file

Passwordless authentication

Connection multiplexing

Host *
        ControlMaster   auto
        ControlPath     /tmp/.ssh-richard-mux-ssh-%r@%h:%p

Known hosts file and key errors

  • Security concern: someone man-in-the-middles the network, directs your connection to their own computer and steals your password.

  • ssh actually has strong security against this.

  • On first connection, you accept a host key:

    The authenticity of host 'something (95.142.168.120)' can't be established.
    ECDSA key fingerprint is 78:64:4c:15:c5:8b:24:39:ee:ab:e1:e5:94:6a:16:de.
    Are you sure you want to continue connecting (yes/no)?
    
  • This can happen if the computer is reinstalled. Less likely is that the NSA is Man-in-the-middle attacking you.

  • The message says that the old key is in line 43 (known_hosts:43). This line needs to be removed, so the new key can be stored.

    • You can just edit the file to remove that line.

    • Shortcut using sed: sed -i LINE_NUMBERd ~/.ssh/known_hosts

      So in this case: sed -i 43d ~/.ssh/known_hosts

    • As long as you have reason to believe that the server has had its key changed, this is not a security concern.

Port forwarding

ssh -L <port>:<hostname>:<other-port>
ssh -R <port>:<hostname>:<other-port>
ssh -D 2345 remote_computer
# Configure SOCKSv5 proxy for localhost:2345

Proxy commands

Host triton
    HostName triton.aalto.fi
    User darstr1
    ProxyCommand ssh-nomux amor-clear nc %h 22

Host amor-clear
    HostName        amor.becs.hut.fi
    User            darstr1
    HostKeyAlias    amor.becs.hut.fi
    ClearAllForwardings yes

scp and sftp

sshfs

sshfs host:path/to/dir  local-dir/
fusermount -u local-dir/

rsync

unison

screen and tmux

mosh

Graphical programs (X11)

nx, x2go, x11vnc, etc

Other