Archive
Tag "Terminal"

Any­one who runs hosted remote servers and has to log into remote ter­mi­nals for reg­u­lar use, it is vital to have short­cuts that allow for quick login. SSH2 is the rec­om­mended way.

On Win­dows, there is the fan­tas­tic SSH2 tool Secure­CRT. Or if you're cash crunched, a com­bi­na­tion of Putty and Putty Con­nec­tion Man­ager works for many.

On Mac OSX and Unix/Linux sys­tems, one doesn't truly need an SSH client at all, because the "Ter­mi­nal" appli­ca­tion is inbuilt. Peo­ple talk of iTerm and such, but I have still to see a value add for such tools.

But one does miss the con­ve­nience of Secure­CRT on OSX, because I have still to find a true Secure­CRT alter­na­tive for the Mac plat­form. Some­thing that allows me to make pre-determined con­nec­tions so I can just click on them to con­nect (which tools like Jel­ly­fiSSH do) and then logs me in directly with­out prompt­ing for a pass­word (which Jel­ly­fiSHH does not do).

So I have sim­ply made aliases in my [code].profile[/code] file, which gets exe­cuted every­time you start your Ter­mi­nal win­dow (so it's a good place to put your short­cuts and any code you wish to exe­cute when the ter­mi­nal starts, such as paths).

  1. Start the Terminal.
  2. Open the pro­file file for the cur­rent user (you).
  3. pico .profile
  4. Enter a new line for our shortcut.
  5. alias s='ssh -2 -p 22 user@host.com'

Quick expla­na­tion for that com­mand in step 3. The let­ter "s" is the short­cut I make for con­nect­ing to the sniptools.com server. Change it to what you wish. This will mean that when I start Ter­mi­nal, all I need to do is type "s" and it con­nects me via SSH to the sniptools.com server. The "-p" switch is an impor­tant one because some of us with para­noid secu­rity set­tings might have a dif­fer­ent port num­ber than the default port 22 for secure SSH. The rest user/host stuff is self-explanatory. The "-2" is to force SSH2 con­nec­tions instead of older vanilla SSH.

Now. Save the pro­file file and source it to try it out:

source .profile

Sourc­ing is only for this one time, for your cur­rent Ter­mi­nal win­dow, which had already exe­cuted the pro­file file *before* we added this alias. When you start a new Ter­mi­nal ses­sion, these aliases et al will be auto­mat­i­cally set for you.

Done. Now your pro­file has the alias for "s". From now when you type "s" in your Ter­mi­nal, it will con­nect, but it will ask you for a pass­word. To get rid of the nag­ging pass­word, we need to cre­ate pub­lic authen­ti­ca­tion key for the domain. This, in fact is what Secure­CRT does behind the scenes on Win­dows too.

Here are the steps to accom­plish this. Run these one-time com­mands in order from the Ter­mi­nal window.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# generate pub and priv keys, leave the passphrase empty
# (simply press ENTER when asked for it)
ssh-keygen
 
#copy the pub key to the remote computer
#(change port number if different from the usual 22)
#change "user" to your user name
#change "host" to your domain name
scp -P 22 ~/.ssh/id_rsa.pub user@host:~/
 
#log on to the remote computer
ssh -p 22 user@host
 
#create the .ssh directory in the root login directory, if it doesn't already exist
mkdir .ssh
 
#append key to file
cat id_rsa.pub >> ~/.ssh/authorized_keys
 
#delete the public key file, no longer needed
rm -f id_rsa.pub
 
#log off the remote server
exit
 
#logon to the remote server, without password prompt
ssh -2 -p 22 user@host

That's it. This is a huge time­saver. Now all I need to do to login to the sniptools.com server is type one let­ter, "s" in the Ter­mi­nal, and I'm on! Fol­low these instruc­tions for each host you con­nect to on a reg­u­lar basis and you'll love the con­ve­nience henceforth.

Read More