TIL: Bash History CLI Shortcuts

## Previous Command's All Arguments
mkdir long_path_here/new_dir
cd !*

## Previous Command's Last Argument
mkdir long_path_here/new_dir
cd !$

or even use $_ instead of !$

## Previous Command's First Argument
mkdir long_path_here/new_dir
cd !^
## History
mkdir long_path_here/new_dir
cd `Esc` `.`
cd `Alt`+`.`

Pressing Esc followed by . will give previous arguments

## "More Options"

!^      first argument
!$      last argument
!*      all arguments
!:2     second argument

!:2-3   second to third arguments
!:2-$   second to last arguments
!:2*    second to last arguments
!:2-    second to next to last arguments

Getting Alt to run on iTerm

  • Open Preferences in iTerm using Command+,
  • Go to Profiles
  • Go to Keys
  • Fix the setting Left option key acts as

    iTerm Preferences - How to Change Alt as Meta key

If you are Terminal on Mac, consider moving to iTerm(if you are not a power user)

  • If you still want this setting in Terminal, look here


Configuring SSH Server


# $OpenBSD: sshd_config,v 1.80 2008/07/02 02:24:18 djm Exp $

# This is the sshd server system-wide configuration file.  See
# sshd_config(5) for more information.

# This sshd was compiled with PATH=/usr/local/bin:/bin:/usr/bin

# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented.  Uncommented options change a
# default value.

Default system level configuration

Change the default port from 22.

Port 2345

I don’t really know what this is

#AddressFamily any

There are can be associate this with either a single address or all the addresses the system has. This is important if your server is part of two networks so that you can use only one of the addresses to bind it to.

#ListenAddress ::

SSH Protocol to use

# Disable legacy (protocol version 1) support in the server for new
# installations. In future the default will change to require explicit
# activation of protocol 1
Protocol 2

Host Key is something to uniquely identify a host.

# HostKey for protocol version 1
#HostKey /etc/ssh/ssh_host_key
# HostKeys for protocol version 2
#HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_dsa_key

# Lifetime and size of ephemeral version 1 server key
#KeyRegenerationInterval 1h
#ServerKeyBits 1024

Log files is the veins of the system. If things go bad, this is where you need to look. Describe what kind of logging should be done

# Logging
# obsoletes QuietMode and FascistLogging
#SyslogFacility AUTH
SyslogFacility AUTHPRIV
#LogLevel INFO


Self explanatory, paranoia in case you don’t want to hit your too often with password retries

# Authentication:
LoginGraceTime 2m
PermitRootLogin no
StrictModes yes
MaxAuthTries 6
MaxSessions 30

Public key authentication for safe and secure way. Generate an RSA token which will generate id_rsa (the private key and should not be shared) and public key, can be passed on to system where you want to login into).

#RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile	.ssh/authorized_keys
AuthorizedKeysCommand none
AuthorizedKeysCommandRunAs nobody

Don’t really know what this is

# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
#RhostsRSAAuthentication no
# similar for protocol version 2
#HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# RhostsRSAAuthentication and HostbasedAuthentication
#IgnoreUserKnownHosts no
# Don't read the user's ~/.rhosts and ~/.shosts files
#IgnoreRhosts yes

Keyboard based authentication of password from the client. If you feel too lazy to type a password all the time see public key authentication section # To disable tunneled clear text passwords, change to no here! #PasswordAuthentication yes #PermitEmptyPasswords no PasswordAuthentication no

Challenge Response Authentication

# Change to no to disable s/key passwords
#ChallengeResponseAuthentication yes
ChallengeResponseAuthentication no

Kerberos is a network login system which is usually used in a medium to big organisations having network logins and multiple servers. If its 2-3 users and couple of servers that share passwords, its better off not setting Kerberos like systems.

# Kerberos options
#KerberosAuthentication no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes
#KerberosGetAFSToken no
#KerberosUseKuserok yes

You don’t want this in a normal server since the handshake itself eats up lot of time. Setting to no disables it

# GSSAPI options
GSSAPIAuthentication no
#GSSAPIAuthentication yes
#GSSAPICleanupCredentials yes
#GSSAPICleanupCredentials yes
#GSSAPIStrictAcceptorCheck yes
#GSSAPIKeyExchange no

# Set this to 'yes' to enable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the ChallengeResponseAuthentication and
# PasswordAuthentication.  Depending on your PAM configuration,
# PAM authentication via ChallengeResponseAuthentication may bypass
# the setting of "PermitRootLogin without-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and ChallengeResponseAuthentication to 'no'.
#UsePAM no
UsePAM yes

Environment variables

# Accept locale-related environment variables

Other custom settings with which you can use the power of SSH and remote system

#AllowAgentForwarding yes
#AllowTcpForwarding yes
#GatewayPorts no

If you want to open a Firefox from a different server. enable to ‘yes’

X11Forwarding no
#X11Forwarding yes
#X11DisplayOffset 10
#X11UseLocalhost yes

Print message of the day

#PrintMotd yes

Enabled by default to let the user know when s/he was logged in last.

#PrintLastLog yes

This is helpful for not timing out the user

#TCPKeepAlive yes
#UseLogin no
#UsePrivilegeSeparation yes
#PermitUserEnvironment no
#Compression delayed
#ClientAliveInterval 0
#ClientAliveCountMax 3
#ShowPatchLevel no
#UseDNS yes
#PidFile /var/run/
#MaxStartups 10

Tunnel is used for using the ssh server as a proxy

#PermitTunnel no

Chroot is a bigger concept which is to restrict environments / environment configuration with dependencies so that they do not interact with the rest of the system. Its like a Virtual Machine in your computer which does not know if its a Virtual Machine or a real server.

#ChrootDirectory none

Display information aka banner on what to do, what not, what the server has etc after logging in.

# no default banner path
#Banner none

Enable SFTP

# override default of no subsystems
Subsystem	sftp	/usr/libexec/openssh/sftp-server

If you want to allow a user to do something or not to do something, this is the place to put it

# Example of overriding settings on a per-user basis
#Match User anoncvs
#	X11Forwarding no
#	AllowTcpForwarding no
#	ForceCommand cvs server

Tips on ssh client configuration