Step 1: Grant yourself administrative privileges
There's some controversy that I'm not even stepping into or even dipping my toes into the water to test the temperature on this debate.
The root user is simply for configuring a server... no need to go beyond that. You often will find yourself making administrative changes where you do not need to be root. Especially if you're not trying to send root authentication all over the network.
So first we'll configure the system you do most of your work on to avoid using root all the time.
Code:
[steve@station ~]$ su -
password...
[root@station ~]# echo steve ALL=(ALL) ALL >> /etc/sudoers
[root@station ~]# exit
[steve@station ~]$
In doing that, you can now sudo everything you need to do administratively. Switching users with the -, implies you want to use that users profile settings in your shell session in bash. Notice the ~ still applies instead of /home/steve when I su to root with the heifen. On top of that, I want to also add... you may not want ALL commands. So review your man pages, /usr/share/doc, or google for the correct syntaxes to limit the amount of sudo commands as you may just want to get to the other system and su to root anyway just to make sure your user can connect. Obviously you can customize this the way you want to but this is just for the example.
Step 2: Preparing for remote administration.
When you prepare to remotely administer your systems, you don't want to be bothered with tons of prompts for a password. So this is your method to avoid this...
First we need to generate a key pair. A private key implies non-repudiation that you are without a doubt, the originator of the keyset and you are who you say you are. The public key, can decrypt the message from the private key. You don't want your private key all over the place. Since you're not using PKI solutions, this is your way of setting up and deploying your keyset to servers that you want to trust you.
This also assumes that you already created a user on the servers for yourself...
Generate The Key Pair
[fedora] denotes the key passphrase I used in this example
Code:
[steve@station ~]$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/steve/.ssh/id_rsa): [enter for the default offering]
Enter passphrase (empty for no passphrase): [fedora]
Enter same passphrase again: [fedora]
Your identification has been saved in /home/steve/.ssh/id_rsa.
Your public key has been saved in /home/steve/.ssh/id_rsa.pub.
The key fingerprint is:
21:21:91:55:60:55:25:06:be:9e:9d:e1:47:c5:44:a3 steve@station.itj-sk.com
[steve@station ~]$
Distribute the Your Public Key
Code:
[steve@station ~]$ ssh-copy-id -i .ssh/id_rsa.pub server1
15
steve@server1's password: [fedora]
Now try logging into the machine, with "ssh 'rhstation1'", and check in:
.ssh/authorized_keys
to make sure we haven't added extra keys that you weren't expecting.
[steve@station ~]$ ssh server1
Enter passphrase for key '/home/steve/.ssh/id_rsa': [fedora]
Last login: Fri Nov 11 12:08:04 2010 from station.itj-sk.com
[steve@server1 ~]$
Now that we copied our public key to the server... we no longer require a password. Now lets eliminate the passphrase to a "sort of" single sign-on.
Step 3: Implementing that "sort of" single sign-on
Now... this part requires some of the GUI for ease... but you can do this manually as well.
Using the GUI, in the system menu, under preferences, and more preferences, you will find "Sessions." In Sessions, on the startup tab. On the startup tab, you will add an entry for "ssh-add"
It will add this entry in your ~/.config/autostart directory.
Code:
[steve@station ~]$ cat .config/autostart/ssh-add.desktop
[Desktop Entry]
Name=No name
Encoding=UTF-8
Version=1.0
Exec=ssh-add
X-GNOME-Autostart-enabled=true
[steve@station ~]$
Once you have this entry... log off and log back in.. or ctrl+alt+backspace. It pretty much does the same function as logoff. Once you log back in, you will receive a prompt to enter your passphrase. Enter your passphrase this one and single time after you enter your password.
Now open a shell and ssh.
Code:
[steve@station ~]$ ssh -X server1
Last login: Fri Nov 11 12:08:04 2010 from station.itj-sk.com
[steve@server1 ~]$
For those who do not know, -X will invoke the automatic transfer for X Server to your desktop. So if you execute for example, "firefox" while ssh -X session is open to the server... Firefox will appear on your desktop. but will have caption next to "Mozilla Firefox" at the top that specifies that its from Server1 as its appearing on your desktop at Station.
All you need to remember is to ssh-copy-id to each system you want to SSH to without being questioned for your password. Here is a verbose look at ssh -v server1.
Code:
[steve@station ~]$ ssh -v server1
OpenSSH_4.3p2, OpenSSL 0.9.8e-fips-rhel5 01 Jul 2008
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to server1 [192.168.1.101] port 22.
debug1: Connection established.
debug1: identity file /home/steve/.ssh/identity type -1
debug1: identity file /home/steve/.ssh/id_rsa type 1
debug1: identity file /home/steve/.ssh/id_dsa type -1
debug1: loaded 3 keys
debug1: Remote protocol version 2.0, remote software version OpenSSH_4.3
debug1: match: OpenSSH_4.3 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_4.3
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-cbc hmac-md5 none
debug1: kex: client->server aes128-cbc hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Host 'server1' is known and matches the RSA host key.
debug1: Found key in /home/steve/.ssh/known_hosts:1
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,gssapi-with-mic,password
debug1: Next authentication method: gssapi-with-mic
debug1: Unspecified GSS failure. Minor code may provide more information
Unknown code krb5 195
debug1: Unspecified GSS failure. Minor code may provide more information
Unknown code krb5 195
debug1: Unspecified GSS failure. Minor code may provide more information
Unknown code krb5 195
debug1: Next authentication method: publickey
debug1: Offering public key: /home/steve/.ssh/id_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 277
debug1: Authentication succeeded (publickey).
debug1: channel 0: new [client-session]
debug1: Entering interactive session.
debug1: Sending environment.
debug1: Sending env LANG = en_US.UTF-8
Last login: Fri Nov 12 12:29:13 2010 from station.itj-sk.local
[steve@server1 ~]$
Next step is to repeat step 1 on the servers to create your entry in sudoers. Then you have a standadized way of performing functions on all of your systems.
You can ssh bounce in between servers like nothing with your ssh-agent providing your key to all the servers you copied your public key to.
I hope this helps anyone looking for a single sign-on like function to manage their infrastructure.
Feel free to send me a private message or email for any suggestions for new how-to's from myself.
Have a great thanksgiving all!!!