0

I'm trying to run a script/shell just after I login via ssh to my host with a "guestUser" the mission of this user is to connect to another remote host via ssh, I've created this user on my host:

guestUser:x:1234:1234::/home/guest:/bin/bash

Then, in guest directory I have a .bashrc file where I add this, following this answer (Linux: How to automatically run commands on SSH login?):

if[[ -n $SSH_CONNECTION ]] ; then
  ssh 192.198.1.99
fi

I did this because I need in this step "guestUser" introduces sshUserInRemoteTwo and sshUserPasswordInRemoteTwo. It does not work. The script tries to log "guestUser" in the remoteHostTwo as "guestUser", that's not the goal, I need the script asks for user/password.

If I get it works: script asks for user/password and login correctly on the second host, then, once SHH connection with the second host is over, guestUser being offline my host; because at the moment, SSH connection is over and user keeps on my host.

0

Try:

ssh <username>@192.198.1.99

Or:

ssh -l <username> 192.198.1.99

Just replace the line in your .bashrc snippet above with one of these forms.

You will be asked for a password for this connection as soon as you log in. You may want to get rid of that using a password-less login.

man ssh

  • ok, and what about once this connection is over, what can i do to logout guestUSer from the first host too? – Di36o Apr 1 '15 at 18:27
  • By default, all SSH servers have a connection timeout. SSH only maintains a connection as long as keep alive packets are continually sent. My suggestion is to simply close the terminal window to close both connections within a few minutes. If you are in single user mode then just type exit, press enter, and type exit once more. – krowe Apr 2 '15 at 0:01
  • I did it, I type exit but that's not the goal, because I need a callback or something similar. A script to logout from the firstHost. I give acces to first host just because this one is the only secure/allowed host to connect to the second, once the SSH session on the second Host, i need logout inmediatly from the first too. Searching in google, i found i "could" use a demon to listen to the SSH session, once it is over, demon run the logout script, but i don't know how to implement that. – Di36o Apr 2 '15 at 17:45
0

If you want the remote will as proxy it is not required to create special user. You may done that by creating auth by key and restrict this key to unconditionally run specified command

man authorized_keys
...
command="command"
         Specifies that the command is executed whenever this key is used for authentication.

In this command you may chain ssh connection.

But better for this purposes use port forwarding.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.