SSH Secure Shell
Used for secure login to remote servers; replaces telnet in most situations. Its default port is 22 (as opposed to telnet's 23), but may be configured to listen on other ports.
NOTE: For many ssh clients, when typing in the password, it does not display any characters, unlike most Windows applications which display *s as you type.
Tunnelling
Command line:
Form
ssh -L <local_port>:<remote_server>:<remote_port> <user>@<remote_server>
Example
ssh -L 10000:server.vcu.edu:80 juser@server.vcu.edu
This tunnels a connection from remote port 80 (the web server) to local port 10000, thus a web server which may not be otherwise accessible can be access by pointing the local web browser to http://localhost:10000 The local port can be any number that is being used by a local service.
Similarly this would be for a ssl enabled web server:
ssh -L 10001:server.vcu.edu:443 juser@server.vcu.edu
Point local web browser to https://localhost:10001
One can also tunnel to the 3rd server, if the server you are connecting to has access, like this:
ssh -L 10443:server2.vcu.edu:443 juser@server1.vcu.edu
Or for a connection to a mysql server:
ssh -L 10002:server.vcu.edu:3306 juser@server.vcu.edu
Connect to mysql database on local port 10002
References
Public Key Authentication
References
All examples are with OpenSSH, commercial SSH is slightly different but the two are interchangeable with some effort
Generate keys:
ssh-keygen -t rsa
Important: Don't enter a passphrase, just press the enter key. This will generate a password-less key file under the ".ssh" directory. You should get two files: id_rsa and id_rsa.pub
Copy public key to remote location and append to authorized_keys file:
ssh-copy-id <account>@<server>:
You should be prompted for your password one last time to confirm.
Test it with:
ssh <account>@<server>
You should be logged in without being prompted for your password.
Remember: Password on remote location can now be locked or changed and ssh keys will still allow authentication.
Set permissions:
.ssh must be 700
.ssh/authorized_keys must be 400
ssh-copy-id
ssh-copy-id -i (identity_file] user@machine
ssh-copy-id is a script that uses ssh to log into a remote machine (presumably using a login password, so password authentication should be enabled, unless you've done some clever use of multiple identities)
It also changes the permissions of the remote user's home, ~/.ssh, and ~/.ssh/authorized_keys to remove group writability (which would otherwise prevent you from logging in, if the remote sshd has StrictModes set in its configuration).
If the -i option is given then the identity file (defaults to ~/.ssh/id_rsa.pub) is used, regardless of whether there are any keys in your ssh-agent. Otherwise, if this:
ssh-add -L
provides any output, it uses that in preference to the identity file.
If the -i option is used, or the ssh-add produced no output, then it uses the contents of the identity file. Once it has one or more fingerprints (by whatever means) it uses ssh to append them to ~/.ssh_authorized_keys on the remote machine (creating the file, and directory, if necessary)
ssh-agent
Consideration for Clusters
Since its assumed that all nodes of a cluster are connected to a secure, private network with shared home directory, there are some steps which will make key authentication faster and easier.
When generating keys, don't enter a passphrase, just press the enter key. This will generate a password-less key file under the ".ssh" directory. A pass phrase will no longer be required.
When copying the public key to the authorized_keys file, copy it to the same .ssh directory once and its done. Make sure authorized_keys is chmod 400. Since this is shared by all compute nodes in the cluster there is no need to copy it to each node.
Single Purpose SSH Key Exchange
Verify command on remote server town.vcu.edu: usr/lib/nagios/plugins/check_load -w 5.0,4.0,3.0 -c 10.0,6.0,4.0
To run the following command remotely from city.vcu.edu to town.vcu.edu with key for this command only
ssh nagios@town.vcu.edu -C "/usr/lib/nagios/plugins/check_load -w 5.0,4.0,3.0 -c 10.0,6.0,4.0"
Create private/public key pair on city.vcu.edu
ssh-keygen -t dsa -f ~/.ssh/check_loadadd command to the public key
cp ~/.ssh/check_load.pub tempfileedit tempfile: command="/usr/lib/nagios/plugins/check_load -w 5.0,4.0,3.0 -c 10.0,6.0,4.0",no-port-forwarding,no-X11-forwarding,no-agent-forwarding ssh-dsslong keynagios@city.vcu.educopy to town.vcu.edu
scp tempfile nagios@town.vcu.edu:on town.vcu.edu, add to authorized_keys file, and set correct permissions
cp -ipd ~/.ssh/authorized_keys ~/.ssh/authorized_keys-BACKUPchmod 600 ~/.ssh/authorized_keyscat tempfile >> ~/.ssh/authorized_keyschmod 700 ~/.sshchmod 400 ~/.ssh/authorized_keysexecute command on city.vcu.edu
ssh -qi ~/.ssh/check_load town.vcu.edu
kwiki SSHKeys between ssh.com and openssh
To create a key under [= openssh] http://safari.oreilly.com/0596004613/linuxsvrhack-CHP-6-SECT-1 (in _Linux Server Hacks_) is good quick explanation.
If the above link doesn't work for you try this one: http://proquest.safaribooksonline.com/JVXSL.asp?x=1&mode=section&sortKey=rank&sortOrder=desc&view=book&xmlid=0-596-00461-3/linuxsvrhack-CHP-6-SECT-1&open=false&g=&srchText=hacks&code=&h=&m=&l=1&catid=&s=1&b=1&f=1&t=1&c=1&u=1&r=&o=1
http://safari.oreilly.com/0596000111/ch11-57817 (in the snail book) has a pretty good lengthy discussion of unattended batch jobs that need ssh in general.
Under openssh, I let acctmgr@aurora log in to nameserv@mira and run the "qi" command, so in [= ~nameserv/.ssh/authorized_keys2] (on mira) I have:
command="/usr/local/sbin/qi" ssh-dss VeryLongBase64EncodingofaKey== acctmgr@aurora.vcu.edu
Under ssh.com, I let nameserv@mira log in to datamart@aurora, so in [= ~datamart/.ssh2/authorization] (on aurora) I have:
Key id_dsa_1024_a.pub
Key id_dsa_1024_nameserv@mira.pub
Command sftp-server
The [= Command] line ought to be changed to an rsync with a more specific command line, like we talked about.
Here's a HOWTO on how to convert ssh.com public keys to openssh (that JimToth wrote in March 2002):
1) Get the public key you're using for authentication onto the new server. In this case, and in most cases when we're converting (as opposed to setting up a new host), it's already in [= $HOME/.ssh2] but in other circumstances you may have to cut and paste, or ftp it over.
2) Make the directory [= $HOME/.ssh] (if it doesn't already exist), and cd to it.
3)
% ssh-keygen -i -f ../.ssh2/id_dsa_1024_d.pub >> authorized_keys2
This converts the public key in [= $HOME/.ssh2/id_dsa_1024_d.pub] and puts
it into the authorized_keys2 file. You may have to use ">" instead
of ">>" if the file doesn't exist and you have noclobber on.
A similar method will also work for converting host keys.
----
Setting up key authentication between two RedHat Linux computers (should work for all openssh to openssh connections) (CGChildr on 16JUN04 )
ssh-keygen -t rsa
ssh <remote> "mkdir .ssh; chmod 0700 .ssh"
scp .ssh/id_rsa.pub <remote>:.ssh/authorized_keys
then test:
ssh <remote>
----
Key Authentication between ssh.com and openssh ( CGChildr on 17JUN04 )
example: aurora to watson
aurora: ssh: SSH Secure Shell 2.4.0 (non-commercial version) on sparc-sun-solaris2.7
watson: SSH Version Sun_SSH_1.0, protocol versions 1.5/2.0.
on local:
issue command: ssh-keygen2, this will by default generate a 1024-bit DSA key pair
> ssh-keygen2
Generating 1024-bit dsa key pair
3 Oo.oOo.oOo.o
Key generated.
1024-bit dsa, cgchildr@aurora, Thu Jun 17 2004 21:15:25
Passphrase :
Again :
Key is stored with NULL passphrase.
(You can ignore the following warning if you are generating hostkeys.)
This is not recommended.
Don't do this unless you know what you're doing.
If file system protections fail (someone can access the keyfile),
or if the super-user is malicious, your key can be used without
the deciphering effort.
Private key saved to /export/home/cgchildr/.ssh2/id_dsa_1024_a
Public key saved to /export/home/cgchildr/.ssh2/id_dsa_1024_a.pub
on local, create an identification file:
> cd .ssh2
> echo "IdKey id_dsa_1024_a" >> identification (use > if file does not exist)
copy public key from local to remote
(I will use sftp on remote to copy it from local )
> pwd
/home/cchildre
> mkdir .ssh2
> cd .ssh2
> sftp cgchildr@aurora.vcu.edu
Connecting to aurora.vcu.edu...
cgchildr@aurora.vcu.edu's password:
sftp > cd .ssh2
sftp > get id_dsa_1024_a.pub
sftp > quit
> ls
id_dsa_1024_a.pub
> pwd
/home/cchildre/.ssh2
on remote, extract from the ssh.com public key an openssh compatible public key
> cd ../.ssh
> ssh-keygen -X -f ../.ssh2/id_dsa_1024_a.pub > authorized_keys
ignore: ---- BEGIN SSH2 PUBLIC KEY ----
ignore: Subject: cgchildr
ignore: Comment: "1024-bit dsa, cgchildr@aurora, Thu Jun 17 2004 21:15:25"
ignore: ---- END SSH2 PUBLIC KEY ----
test by making a connection from local to remote:
> ssh cchildre@watson.vcu.edu
Host key not found from database.
Key fingerprint:
xohip-symeb-gibyb-gabot-semot-helyt-doduc-vizik-kehig-razun-gexex
You can get a public key's fingerprint by running
% ssh-keygen -F publickey.pub
on the keyfile.
Are you sure you want to continue connecting (yes/no)? yes
Host key saved to /export/home/cgchildr/.ssh2/hostkeys/key_22_watson.vcu.edu.pub
host key for watson.vcu.edu, accepted by cgchildr Thu Jun 17 2004 21:29:45
Authentication successful.
Last login: Thu Jun 17 17:10:40 2004 from aurora.vcu.edu
Sun Microsystems Inc. SunOS 5.9 Generic May 2002
Note the .ssh2 directory on the remote is no longer needed for this authentication to take place. The key is in the authorized_keys file.
References:
http://ssh.com/support/documentation/online/ssh/adminguide/41/Server_Configuration-6.html
http://bumblebee.lcs.mit.edu/ssh2/