Ssh – Multiple Users use Script to Access Remote Server via Passwordless SSH

bashredhatscriptingssh

I am currently setting up a linux box that is tied into Active Directory. This box will allow users to SSH into it with their AD username and password to gather information (Box A). The issue is I am trying to create a function in /etc/bash.bashrc so the users has to do is type "get_info" for example, the function will SSH into a remote machine (Box B) run a command and output the information back to the user.

The issue with this is, I have generated a rsa key on Box A, added it to the Box B authorized_keys and it works fine. The issue I am running into is, how do I set this up one time for the current users and any new user who logs into Box A.

Is there a better approach than what I am currently doing. Essentially I just need to connect to the remote box, run a command, output the information back to the user and that is it. How can I allow new users to connect via a script to the remote box without having to generate RSA keys for them.

The get_info fuction will be supplied a value 'get_info 012345' and returns the results.

Best Answer

What is needed:

  • Shared keys by users
  • Create common script on server
  • In your ssh config limit user to particular commands:

    command="/bin/myscript.sh",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty ssh-dss AAAAB3....o9M9qz4xqGCqGXoJw= user

  • Create script on local box or in their home folders that executes an ssh command to the remote server, executes the script on server and then outputs

  • If you need input into the remote session, you could run your local script

    ./local.sh 01234

Which executes:

ssh user@remote '/bin/myscript.sh $1'

It is interpreted as

ssh user@remote '/bin/myscript.sh 01234