SSH keys and command limiting ...

Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers SSH keys and command limiting ...
# 1  
Old 01-28-2008
SSH keys and command limiting ...

Hi, I've just been trying to setup so that server1 can ssh into server2 and execute a limited set of commands only without password login. I want it also to be able to login with a password if no command given at all though (bit I'm stuck on).

I have got this almost working with authorized_keys and

from="hostofserver1",command="/" rest of key> in authorized_keys file.

This all works fine, so I can "ssh server2 ls" and all works fine (as I have allowed ls in the script). If I enter a wrong command it doesn't do anything and kicks me out. So far so good.

Only problem is that with that key/entry in place, I can no longer login to the box normally if wanted with a normal password.

So I want to be able to "ssh server1 ls" checks keys and it works, no password needed. Or just "ssh server1" and it asks for a password, and assuming correct gives me a shell.

Any ideas, just the last bit I'm stuck on.

Thanks in advance.
# 2  
Old 01-29-2008
I don't believe this will work quite how you want it too.

By using the command option, you are limiting that key to the specified commands, including the shell. To allow it you would need to add the shell to the command but that makes what you are trying to achieve pointless.

Here is what I would do:

Keep the key you have now, and use that like you have been. Create a second identity file with a second key.

ssh-keygen -f /path/new_id_rsa

Do not allow add it authorized_keys on the remote host and launch it like this:

ssh -i /path/new_id_rsa hostname

It should prompt for a password as normal. You could create a wrapper alias to save having to type the path to the identity file.

Please note this is untested, and there are probably better ways to do it. I have made a few assumptions (like it seems everyone connects to this system with the same account?).
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find active SSH servers w/ ssh keys on LAN

Hi, I am trying to complete my bash script in order to find which SSH servers on LAN are still active with the ssh keys, but i am frozen at this step: #!/bin/bash # LAN SSH KEYS DISCOVERY SCRIPT </etc/passwd \ grep /bin/bash | cut -d: -f6 | sudo xargs -i -- sh -c ' && cat... (11 Replies)
Discussion started by: syrius
11 Replies

2. Red Hat

Configuring the SSH keys..

I am currently working on setting up a server to scp some files over for backup purposes. Server 1 - Bob (Appliance) Server 2 - Sana (RH 5) Server 1 - 1 - Generated RSA2 2 - Collected the public key to be input on the backup server = Sana Server 2 - 1 - This is were I am stuck the... (4 Replies)
Discussion started by: NelsonC
4 Replies

3. Solaris

help with SSH keys

Hello, I could use some help with my ssh keys and agent. This is the issue. I have 2 different UNIX systems at work. One is the normal Solaris servers with my uid being the same throughout all the servers. I now have a different system for my desktop. A contractor came in and installed some SUN... (0 Replies)
Discussion started by: bitlord
0 Replies

4. Shell Programming and Scripting

How helpful are ssh keys?

Hi frnz, I work in an environment, where I need to login to multiple UNIX sessions(Always types my password when prompted for) I heard of ssh keys which provides us a valid authentication and that avoids us typing the password. Now I want to generate the ssh keys and use in my... (2 Replies)
Discussion started by: dnam9917
2 Replies

5. Shell Programming and Scripting

What are public keys in ssh and how do we create the public keys??

Hi All, I am having knowledge on some basics of ssh and wanted to know what are the public keys and how can we create and implement it in connecting server. Please provide the information for the above, it would be helpful for me. Thanks, Ravindra (1 Reply)
Discussion started by: ravi3cha
1 Replies

6. UNIX for Dummies Questions & Answers

SSH keys

Hi everyone, i wanted to generate ssh keys so that i can include the public key in the remote sever, so that for subsequent logins, i can do away with the keying in of the password. I consulted the man ssh-keygen man pages. "..Normally each user wishing to use SSH with RSA or DSA... (1 Reply)
Discussion started by: new2ss
1 Replies

7. UNIX for Dummies Questions & Answers

ssh public keys

Hello*! I have problems with public keys. On one side i have Solaris 10, and on other side is HP UNIX. I created public keys on Solaris with "ssh-keygen -t rsa", append key to ~user/.ssh/authorized_keys on remote machine, and tried to connect with ssh without password. But for some... (1 Reply)
Discussion started by: ghost01
1 Replies

8. UNIX for Advanced & Expert Users

SSH Keys Help

Hello, I'm wondering if anyone has a step-by-step instruction set for setting up ssh keys? I've gone through many of the manuals online (most seem to be from the same source) and it's a little bit unclear when the documentation is talking about the server versus the client machine. I'm missing... (1 Reply)
Discussion started by: sysera
1 Replies

9. UNIX for Dummies Questions & Answers

question about limiting the display from the ls command

hey guys im rly new to unix. im attempting to list the 5 largest files in a directory. so i got this far... ls -lR | sort -r and this lists all files by filesize, how can i limit this to only the 5 largest? (4 Replies)
Discussion started by: Aesop
4 Replies
Login or Register to Ask a Question