How do I establish a bidirectional SSH Tunnel [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
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

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 tunnel to another computer using a middle computer? SSH [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 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)

How to download a file from server using SSH? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Closed 10 years ago.
Locked. This question and its answers are locked because the question is off-topic but has historical significance. It is not currently accepting new answers or interactions.
I need to download a file from server to my desktop. (UBUNTU 10.04) I don't have a web access to the server, just ssh.
If it helps, my OS is Mac OS X and iTerm 2 as a terminal.
In your terminal, type:
scp your_username#remotehost.edu:foobar.txt /local/dir
replacing the username, host, remote filename, and local directory as appropriate.
If you want to access EC2 (or other service that requires authenticating with a private key), use the -i option:
scp -i key_file.pem your_username#remotehost.edu:/remote/dir/foobar.txt /local/dir
From: http://www.hypexr.org/linux_scp_help.php
You can do this with the scp command. scp uses the SSH protocol to copy files across system by extending the syntax of cp.
Copy something from another system to this system:
scp username#hostname:/path/to/remote/file /path/to/local/file
Copy something from this system to some other system:
scp /path/to/local/file username#hostname:/path/to/remote/file
Copy something from some system to some other system:
scp username1#hostname1:/path/to/file username2#hostname2:/path/to/other/file
scp is certainly the way to go, but for completeness you can also do:
$ ssh host 'cat /path/on/remote' > /path/on/local
or
$ cat /path/on/local | ssh host 'cat > /path/on/remote'
Note, this is UUOC, but < /path/on/local ssh host 'cat > /path' could cause unnecessary confusion.
And to proxy between two hosts:
$ ssh host1 'cat /path/on/host1' | ssh host2 'cat > /path/on/host2'
If the SSH server support SFTP subsystem (this is part of SSH, and unrelated to FTP), use sftp. If it don't, try scp.
CyberDuck support all of them.

SSH Port forwarding in a ~/.ssh/config file? [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 11 years ago.
Improve this question
So I typically run this command a lot:
ssh -L 5901:myUser#computer.myHost.edu:5901
I use it to do VNC over SSH.
How do I convert that command into something that will work in a ~/.ssh/config file?
ex:
host yam
HostName yam.myHost.edu
User myUserName
all I want to do is type:
ssh yam
And have it open a SSH shell with a local listen port, and a remote port forwarded to it.
Suggestions?
You can use the LocalForward directive in your host yam section of ~/.ssh/config:
LocalForward 5901 computer.myHost.edu:5901

Resources