set hostlist=(`cat ~/.ssh/known_hosts | cut -f 1 -d ' ' | cut -f 1 -d ',' | uniq`)
complete ssh 'p/1/$hostlist/' 'p/2/c/'
This are my notes in the fields of computer science and technology. Everything is written with ABSOLUTE NO WARRANTY of fitness for any purpose. Of course, feel free to comment anything.
Showing posts with label shell rc file. Show all posts
Showing posts with label shell rc file. Show all posts
Thursday, December 31, 2009
ssh autocompletion in tcsh
I wrote the following for my .tcshrc to get some autocompletion for ssh.
Sunday, October 11, 2009
Starting ssh-agent from .tcshrc
While connecting to a server using SSH, you need either to provide a password or to use a public-private key pair to identify yourself. The latter is interesting, as you don't have to write your password each time. A copy of the public key must be saved in the computer acting as ssh server under ".ssh/authorized_keys", the private key stays only on the client computer.
However for security reasons it is strongly reccomended to set a password on the key file. Otherwise anyone who can steal your key somehow (like accessing your computer physically), can steal your identity. But if your key file has a password, then you would have to write the password each time, so it wouldn't be much better than using passwords instead of keys in the first time. Luckily there is a solution: ssh-agent and ssh-add. ssh-agent runs as a deamon and remembers the password to your key. ssh-add allows you to tell ssh-agent the password.
As ssh-agent keep running when you log off your session, you may add some lines to your shell startup script, to test if ssh-agent is running, otherwise to start it and ask you the password (via ssh-add). In the github guides there is a script for bash (). I adapted it to use it in tcsh, which I use as a shell. Here is it (I added these lines at the bottom of my .tcshrc file, only *before* setting the prompt explicitely, as I used it to distinguish interactive sessions from non-interactive ones):
However for security reasons it is strongly reccomended to set a password on the key file. Otherwise anyone who can steal your key somehow (like accessing your computer physically), can steal your identity. But if your key file has a password, then you would have to write the password each time, so it wouldn't be much better than using passwords instead of keys in the first time. Luckily there is a solution: ssh-agent and ssh-add. ssh-agent runs as a deamon and remembers the password to your key. ssh-add allows you to tell ssh-agent the password.
As ssh-agent keep running when you log off your session, you may add some lines to your shell startup script, to test if ssh-agent is running, otherwise to start it and ask you the password (via ssh-add). In the github guides there is a script for bash (). I adapted it to use it in tcsh, which I use as a shell. Here is it (I added these lines at the bottom of my .tcshrc file, only *before* setting the prompt explicitely, as I used it to distinguish interactive sessions from non-interactive ones):
# start ssh agent if not started yet
set SSH_ENV = "$HOME/.ssh/environment"
unset SSH_AGENT_RUNNING
if (-f $SSH_ENV) then
source $SSH_ENV
ps $SSH_AGENT_PID > /dev/null && set SSH_AGENT_RUNNING
endif
if ($?prompt && ! $?SSH_AGENT_RUNNING) then
echo "Initializing SSH agent..."
/usr/bin/ssh-agent | sed 's/^echo/#echo/' >! $SSH_ENV
chmod 600 $SSH_ENV
source $SSH_ENV
echo "done: ssh-agent is now running, PID $SSH_AGENT_PID"
/usr/bin/ssh-add
endif
Saturday, September 12, 2009
Colors in grep
To turn on colors in grep, you may add --color=auto to the GREP_OPTIONS environment variable. The way to do it is of course shell-dependant. E.g. add the following to your shell rc file:
export GREP_OPTIONS='--color=auto'
Sunday, August 9, 2009
GIT_PAGER and LESS colors
I was wondering why, working on two different machines, I was able to display git-log and git-diff colors on one machine and not on the other, despite the same git configuration file ~/.gitconfig:
and no particular settings regarding colors in <repository>/.git/config
[color]
diff = auto
status = auto
branch = auto
log = auto
Although I was not using a Mac, the solution was in this blog post: that is, setting the GIT_PAGER variable to cat was already solving the problem; GIT_PAGER sets which program should be used by git to display for example the diff and log output (default less).
The actual problem was in less and how it outputs ANSI color ESC codes. A solution, similarly to what suggested in that post, was to set the LESS variable to -R and leave GIT_PAGER unset, as it originally was. Regarding the other options suggested in the blog post for LESS, -X and -e have no influence on color display, and -R is probably better than -r; in particular, this in an extract of the less manual, at the -r/-R section, explaining why:
The actual problem was in less and how it outputs ANSI color ESC codes. A solution, similarly to what suggested in that post, was to set the LESS variable to -R and leave GIT_PAGER unset, as it originally was. Regarding the other options suggested in the blog post for LESS, -X and -e have no influence on color display, and -R is probably better than -r; in particular, this in an extract of the less manual, at the -r/-R section, explaining why:
-r or --raw-control-chars
Causes "raw" control characters to be displayed.
[...] Warning: when the -r option is used, less cannot
keep track of the actual appearance of the screen
(since this depends on how the screen responds to
each type of control character). Thus, various display
problems may result, such as long lines being split
in the wrong place.
-R or --RAW-CONTROL-CHARS
Like -r, but only ANSI "color" escape sequences are
output in "raw" form. Unlike -r, the screen appearance
is maintained correctly in most cases. [...]
Thursday, October 11, 2007
bash startup
In interactive mode bash executes some startup scripts. First thing to know is if it is a login shell or not a login shell:
* login shell: (executes more things)
(1) general settings for all users are in: /etc/profile
(2) personal settins may be in: (first one readable)
~/.bash_profile
~/.bash_login
~/.profile
(3) before logout: ~/.bash_logout
* non-login:
>bash => ~/.bashrc
>bash => ~/.bashrc
>bash --norc => nothing
>bash --rcfile filename => specify another rc file
>bash --rcfile filename => specify another rc file
Subscribe to:
Posts (Atom)
Labels
software installed on my laptop
(13)
windows software
(12)
personal settings
(10)
linux software
(8)
rails
(7)
shell rc file
(6)
linux basics
(5)
C basics
(4)
color the shell
(4)
ruby
(4)
connection to remote servers
(3)
git
(3)
mutimedia software
(3)
rake tasks
(3)
shell
(3)
active scaffold
(2)
backup
(2)
disk analysis
(2)
less
(2)
oracle
(2)
rails migrations
(2)
rails on oracle
(2)
sql
(2)
ssh
(2)
symbolic links
(2)
top open source projects
(2)
virtualbox
(2)
GUI programming
(1)
MIT
(1)
active record
(1)
algorithms
(1)
applications
(1)
apt
(1)
attr_hidden
(1)
bash
(1)
capistrano
(1)
cms tools
(1)
color picker
(1)
common errors
(1)
cooltips
(1)
data recovery
(1)
data structures
(1)
dvd43
(1)
endline chars
(1)
expression engine
(1)
ftp clients
(1)
gimp
(1)
grep
(1)
handbrake
(1)
hard disk failure
(1)
image conversion
(1)
image editing
(1)
inkscape
(1)
java software
(1)
javascript
(1)
jdiskreport
(1)
linux compact guides
(1)
ls
(1)
online lectures
(1)
oracle lob
(1)
photo manipulation
(1)
php
(1)
polymorphic associations
(1)
prototype
(1)
putty
(1)
rails plugins
(1)
rake
(1)
rsync
(1)
ruby blocks
(1)
scanf
(1)
scite
(1)
script
(1)
scripteka
(1)
sftp clients
(1)
sort_by :sql
(1)
suffix array
(1)
synctoy
(1)
tcsh
(1)
timms
(1)
unlocker
(1)
vector graphics
(1)
vi
(1)
video lectures
(1)
vlc media player
(1)
windows alpha blender
(1)
winscp
(1)
xslt xml
(1)
About Me
- Giorgio Gonnella
- Hamburg, Hamburg, Germany
- Former molecular biologist and web developer (Rails) and currently research scientist in bioinformatics.