Open an SSH tunnel as a different user

0

I routinely open an SSH tunnel to access a service running on a remote machine: /usr/bin/ssh -L portA:localhost:portB remote.host.com -N &. The problem I'm facing right now is that unlike usually, I need to access the service as a different user. When I SSH to remote.host.com and try accessing the service using sudo -u userX localhost:portB, it works fine as I have permissions over this user.

userX does not exist on my local machine and I essentially want to be able to access everything I can access on the remote host directly from my local machine. Is there any way to do that ?

PS: I can sudo as userX but don't have their password (and shouldn't have it). I'd like to be more accurate but my understanding of Linux permission model is a bit fuzzy in all fairness.

Dici

Posted 2017-07-19T21:42:53.127

Reputation: 103

Can you connect with userX@remote.host.com? – doriclazar – 2017-07-19T21:52:32.060

When I try, I'm asked to provide the password of the user, which I don't have. I can only sudo as the user once I connected to the host as myself. – Dici – 2017-07-19T21:54:22.203

Answers

1

Generate a key pair on your local machine for userX (ssh-keygen), ssh to the remote server, and add public key to the list of authorized keys. Then sudo in ssh config file, and uncomment public key authentication as allowed. It shouldn't ask about password then.

Try not to lock yourself out. Read some docs first if you are unsure.

doriclazar

Posted 2017-07-19T21:42:53.127

Reputation: 166

Haha, you scared me with the last bit. I'll take some time to think it through and will come back to you when I try (probably tomorrow). Thanks for your answer :) – Dici – 2017-07-19T22:10:45.100

1Thanks, I used a similar approach to what you suggested and it worked – Dici – 2017-07-20T15:33:49.860