Archive for the ‘BASh’ Category

Automate SSH logins with RSA/DSA keys

Monday, December 10th, 2007

Automated Shell LoginOften when you are administrating remote Linux servers, you tend to login to the servers via your favorite shell. And every time when you login you are prompted for a user name + password to authenticate your session. This gets a bit tedious if you have many passwords to remember for different logins. This is were ssh keys can be used to save you from typing your credentials for every ssh login you execute. Once you have setup your SSH key, you are just one step away from making your life a whole lot easier.

I have put together a shell script which saves me the trouble of remembering various combinations of user names + passwords. It looks something like this: cat ~/.ssh/id_dsa.pub | ssh jeffery@example.com "(mkdir .ssh&>/dev/null; chmod 700 .ssh && cat - >> .ssh/authorized_keys ) && chmod 600 .ssh/authorized_keys" (more…)

The Shell’s History

Saturday, October 1st, 2005

The Shell’s History

The shell remembers the history of your last typed commands. It is what you see when you use the up and down keys in Bash.

There are plenty of ways to use this history! I will write some tips here that I know but don’t hesitate to add more in comments.

  • the ! tip: starting a line by ! followed by the first few letters of a previous command recalls it, very useful !
  • ! followed by a number recalls this command.
  • the !? tip: is somewhat similar but doesn’t only look at command starting with the following letters but containing them !
  • ‘#’ comments the commands but still records it. (if you have something to check while typing a long command)
  • of course the history command shows you the last commands ;)
  • [ctrl-r] put you in history mode
  • if you don’t like this feature, you can filter it with HISTIGNORE

example :

export HISTIGNORE="&:ls:\[bf\]g:exit"

suppresses duplicate commands, the simple invocation of ‘ls’ without any arguments, and the shell built-ins bg, fg, and exit:

And if you include the expression “[ t]*” in the HISTIGNORE string, you can suppress history recording at will for any given command just by starting with a space!