how to tunnel to another computer using a middle computer? SSH [closed] - linux

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I am in my local computer, and i just want to test reverse ssh so that i access computer 2 and access computer 3 through computer 2 and make computer 3 respond to me in lets say i want to access postgresql on computer 3.
how to do that with ssh and using ports? 5432 is the port of sql
my approach is this:
ssh -L 3000:localhost:5432 <ipaddressof the 2nd computer>
so im inside 2nd computer now.
in the terminal again i type:
ssh -L 3000:localhost:5432 <ipaddress of the 3rd computer>
and im inside the 3rd computer now. And i dont know what to do anymore, how to access its sql?
i tried this code which doesn't work:
psql -U myusername -p 3000

Try the following:
ssh -L localhost:3000:<ip address 3rd computer>:5432 <ip address 2nd computer>
And then:
psql -U myusername -h localhost -p 3000
This works if:
The 2nd computer has access to the 3rd computer
The sshd config on the 2nd computer allows TCP forwarding (default is yes)

Related

How to auto connect jumper or proxy and server with one command ssh [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 4 years ago.
Improve this question
I remember one of my friend is using ssh file configuration to make it be done, but I can't find the command that should be written in that file to achieve this result.
So what he did is just type the command
ssh [alias of the server]
and the shell automatically go to jumper (proxy) submit the password in there,
then go to the server and again submit the password there, so he doesn't need to re-enter password during ssh into the server.
Another question, is this able to be done for Windows server?
You can use something like this:
Host jump
User [username]
HostName [ip address]
Host [server ip address] [server alias]
HostName [server ip address]
User [username]
Port [port]
ProxyCommand ssh -q -W %h:%p jump 2>/dev/null
Host Jump is a proxy server.
The command that will help you take a leap on the proxy server then continue to the server is ProxyCommand.
%h: is using your username
%p: is using your password from id_rsa.pub.
Reference: https://www.ssh.com/ssh/config/
I've never tried this except with public key authentication, but assuming:
You want to ssh from origin-box to target-box
target-box has a network name of target.box.domain
origin-box is not authorized on target-box
proxy-box is authorized on target-box
origin-box is authorized on proxy-box
You ssh/config on origin-box would be something like:
Host target-box
ProxyCommand ssh -q proxy-box -W target.box.domain

Find out how many SSH connections currently exist [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I'm using a simple shell script on my Linux server which checks if an rsync job is running or if any client accesses some directories from the server via Samba. If this is the case then nothing happens, but if are there no jobs and Samba isn't used than the server goes into hibernation.
Is there any simple command which I can use to check if an SSH connection to the server exists? I want to add this to my shell script so that the server doesn't hibernate if such a connection exists.
Scan the process list for sshd: .
Established connections look something like this: sshd: <username>…
ps -A x | grep [s]shd
should work for you.
use who command
it gives output like
username pts/1 2013-06-19 19:51 (ip)
You could parse that to see how many non locals are added and get their usernames (or there are options see man who for more info
gives a count of how many non localhost users there are
who | grep -v localhost | wc -l

How to find out which process is using localhost:80? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I'm using linux mint xfce edition, my localhost:80 was used by some program but I don't which one, when I open firefox and visit localhost:80, it says
It works!
This is the default web page for this server.
The web server software is running but no content has been added, yet.
I've tried to use lsof -i #localhost:80, but it returns nothing.
netstat -anpt | grep :80 as root user should list process using port 80.
With your web browser closed it can help you identify the process.
Try this:
# fuser -n tcp 80
From the manpage:
-n SPACE, --namespace SPACE
Select a different name space. The name spaces file (file names,
the default), udp (local UDP ports), and tcp (local TCP ports)
are supported. For ports, either the port number or the symbolic name can
be specified. If there is no ambiguity, the shortcut
notation name/space (e.g. 80/tcp) can be used.

How do I establish a bidirectional SSH Tunnel [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
Is it possible to do the following via an SSH tunnel...
Host-1 establishes an SSH connection to a Remote Server
I wish to log into the Remote Server and execute commands over SSH back on Host-1
Host-1 is a device that I will not have access to directly. Host-1 is set up to automatically establish an SSH connection to a remote server via cron. At any point while Host-1 has established an SSH connection to the Remote Server, I wish to log into the Remote Server in order to perform maintenance on Host-1 via SSH.
I am looking for an example of how this would work if its possible.
Like this:
host1$ ssh -N -R 8822:localhost:22 remote.host.com
The optional -N says "don't execute a command" (helpful to prevent accidents caused by leaving remote shells laying around.)
Now from remote, you can SSH to host1 like this: (The remote port 8822 forwards to host1, but only on the loopback interface.)
remote$ ssh -p 8822 localhost
For extra credit, you can export the forwarding to the whole world, allowing anyone get to host1 by hitting remote's port 8822. (Note the extra initial colon)
host1$ ssh -N -R :8822:localhost:22 remote.host.com

how to make ssh fail if any parameter is wrong [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I'm using the command ssh -i /home/ssh_keys/10_1_1_127 root#10.1.1.127 date for checking the date on some other machine,
If some parameter is wrong, like the user, the ip or the identity file doesn't exists,
ssh asks for password
for example, if I write ssh -i /home/ssh_keys/10_1_1_1277 root#10.1.1.127 date
whilst /home/ssh_keys/10_1_1_1277 doesn't exists, I get:
root#10.1.1.127's password:
I wanted to know if it is possible, and if so, then how to make ssh fail if some parameter isn't right, so ssh won't ask me for a password if I enter wrong parameters...
Thanks
All these changes should be done via root or a sudo enabled user.
In /etc/ssh/sshd_config set the following entries to no:
ChallengeResponseAuthentication no
PasswordAuthentication no
UsePAM no
If you need help finding those specific lines, use grep:
grep -n "PasswordAuthentication" /etc/ssh/sshd_config
^^or whatever^^
This outputs the line number
Then restart ssh
/etc/init.d/ssh restart
or
service ssh restart
depending on your flavor of Linux.

Resources