Use Readline shortcuts
At the bash prompt, you can use the default readline keybindings, these are similar to Emacs ones. Many of these are also available within other programs that use readline, such as the Python interpreter.
Here are some useful ones:
Ctrl-A Beginning of Line
Ctrl-E End of Line
Ctrl-U Kill (cut) everything left of cursor
Ctrl-K Kill (cut) everything right of cursor
Ctrl-W Kill (cut) the single word before the cursor
Ctrl-Y Yank (paste) the text back
Ctrl-L Clear Screen
Ctrl-D Exit
Ctrl-R Reverse interactive-search, (attempt to complete what is currently being typed using the history file)
SSH without Passwords
If you login to a remote machine often and you get bored of typing the password, then you can use public key cryptography instead.
The way it works is that the remote machine has a copy of your local machine's public key, it can then use that to check that your local machine is really your machine, and so let you in.
To start with, on the local machine, see if you already have a key pair:
ls ~/.ssh/id_?sa.pub
If not, then make one:
ssh-keygen -t dsa
Now you need to copy your public key to the remote host. On the local machine run:
scp ~/.ssh/id_?sa.pub remotehost:
Now we login to the remote server:
ssh remotehost
Append the public key to your authorized keys file
cat id_?sa.pub >> ~/.ssh/authorized_keys
Now you can login without passwords. Make sure the security of your machines is well thought out. Use disk encyption if possible.
Create a script directory in home directory
I often talk about random Python or bash scripts. The easy way to use them on Linux is to make a dedicated script directory for these.
mkdir ~/bin
Add it to your shell's path. Edit ~/.bashrc and add:
export PATH=$HOME/bin:$PATH
Now all the scripts that you add to ~/bin are always available. This makes things a lot more flexible and fun as you can try out various scripts by dropping them in ~/bin and then deleting them when you are bored of them.
<p>Thanks dude, I have a machine on my local network that I ssh into all the
time and it never even occured to me that there was a passwordless login
option - thats gonna save a lot of irritation for me <img src="/static/forum/img/smilies/smile.png"></p>
<p>Gah, don't use passwordless SSH keys! Use ssh-agent instead - it achieves the
same thing, but with one less possible-security problem..
<a class="reference external" href="http://upc.lbl.gov/docs/user/sshagent.html">http://upc.lbl.gov/docs/user/sshagent.html</a></p>
<p>If you don't like the emacs'ish keybindings, in bash you can run "set -o vi"
and Esc toggles between regular insert mode, and vi-command mode (where 'dw'
delets words, 'j' scrolls up the command-history etc). That said, the emacs'y
bindings are probably more practical (modal editing in a command line isn't
terribly useful)..</p>
<p>I'll just add:</p>
<p>Meta-b One word back
Meta-f One word forward
Meta-d kill word forward</p>
<p>...to the list of nifty keyboard shortcuts in the shell.</p>
<p>Awesome-- never knew about the cut/paste commands within bash. That'll be a
lifesaver some day. Some additional bits of awesome:</p>
<p>For those times you don't want to type out an argument that you just typed
again, you can use !:# as a stand-in or a previous line's arguments. Once
you hit enter, the command is then printed out so you can see what you did,
or in zsh you can hit tab and it will autocomplete.</p>
<p>omg:~ keke$ mv filename1 filename2
omg:~ keke$ mv !:2 !:1
mv filename2 filename1
omg:~ keke$</p>
<p>And... For those times that you need to re-enter a whole line, say you forgot
to sudo a command, there's !!</p>
<p>omg:~ keke$ port install naim
Error: permission denied
omg:~ keke$ sudo !!
sudo port install naim
Password:
---> Fetching naim</p>
<p>It's freaky how many weird shortcuts there are in bash, and googling finds
many. For instance, there's a find-replace shortcut for the last command:</p>
<p>omg:~ keke$ echo "this is so horrible"
this is so horrible
omg:~ keke$ ^horrible^amazing
echo "this is so amazing"
this is so amazing</p>
<p>Go Bash!</p>
<p>Ah, addendum-- you can expand the shortcuts in bash to make sure you know
what you're typing by entering a space and hitting tab.</p>
<p>Ooh, and meta, ctrl+e writes out the command too; instead of space, tab.
They probably behave differently.</p>
<p>Reading the man page for bash now, and it's just crazy.</p>
<p>I agree with DBR, never ever use passwordless public keys. Yes they're convinient, but there's a much easier way (sshagent as DBR mentions). In fact, in Ubuntu and Mac OS, there are graphical SSH Agents that automatically pop up when you have a key with a passphrase, asking if you want the OS to remember it (basically, doing what sshagent does, but graphically). For the sake of typing a passphrase ONCE, you have secure keys that - if stolen - still cannot be used.</p>
<p>Useful tips though! <img src="/static/forum/img/smilies/smile.png"> (I have subscribed to your RSS)</p>
<p><a class="reference external" href="http://jalada.havennetworks.com">http://jalada.havennetworks.com</a></p>