LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Is there anyway to run a remote command via ssh as if it's run from the local server? (https://www.linuxquestions.org/questions/linux-general-1/is-there-anyway-to-run-a-remote-command-via-ssh-as-if-its-run-from-the-local-server-4175723493/)

GenericLinuxUser 03-27-2023 08:05 AM

Is there anyway to run a remote command via ssh as if it's run from the local server?
 
Hi,

I am working on setting up an LDAP connection on a server. On the server I want to use ldapsearch for testing but it's not installed. I do have access to ldapsearch installed on another server. However, the AD server is only seen from the server that does not have ldapsearch installed. I've asked our sysadmins to install ldapsearch on the needed server but there's a bureaucratic hold up and I'm trying to see if I can somehow run the remote command as if I'm on the server and just get this done.

In other words, I can see an AD server (XXX) from server YYY

myuser@YYY: ping -c 1 XXX
PING XXX (xxx.xxx.xxx.xxx) 56(84) bytes of data.
64 bytes from XXX (xxx.xxx.xxx.xxx): icmp_seq=1 ttl=121 time=32.6 ms
--- XXX ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 32ms


I can't from ZZZ

myuser@ZZZ: ping -c 1 XXX
ping: XXX: Name or service not known


I can run ldapsearch from server ZZZ on server YYY via ssh

myuser@YYY: ssh myuser@ZZZ ldapsearch -x -h XXX -p 389 -D "CN=myuser,CN=users,DC=example,DC=Com" -W -b "DC=example,DC=Com" cn=myuser


But this of course returns "Can't contact LDAP server" because ZZZ does not know of XXX. Is there anyway to run a remote command via ssh as if it's run from the local server?

Turbocapitalist 03-27-2023 08:33 AM

You could try a reverse tunnel to forward the LDAP port and then connect to the LDAP port on the address for localhost on the remote system.

GenericLinuxUser 03-27-2023 09:03 AM

Thanks Turbocapitalist, reverse tunneling seems promising, I'll look into that

pan64 03-27-2023 10:55 AM

you just need to run the command on ZZZ: ssh myuser@YYY ldapsearch ....

GenericLinuxUser 03-27-2023 01:24 PM

pan64, if I do that I get "bash: ldapsearch: command not found" because ldapsearch is not installed on YYY

yvesjv 03-27-2023 01:52 PM

Also copy the certs for making life a bit easier
https://www.thegeekstuff.com/2008/11...n-ssh-copy-id/


All times are GMT -5. The time now is 10:07 AM.