0

In order to access to my pc at work i do:

ssh -AY myusername@server_of_the_company

and then:

ssh -AY myusername_at_my_pc@ip_address_of_my_pc

I read about ssh tunnelling but i cannot make it work. Which command should I use to connect directly from local to my pc at work?

Bonus question, how to setup scp to copy back and forth from local to my_pc?

muru
  • 193,181
  • 53
  • 473
  • 722
Pierpaolo
  • 141
  • 1
  • 6

2 Answers2

3

You can do:

ssh -L 2222:ip_address_of_my_pc:22 -AY myusername@server_of_the_company

This will forward connections to port 2222 of localhost to port 22 of your PC.

Then, to connect to your PC, you can do (from your local system):

ssh -AY -p 2222 myusername_at_my_pc@localhost

scp works similarly.

muru
  • 193,181
  • 53
  • 473
  • 722
  • from my local system to localhost? what do you mean? – Pierpaolo Dec 24 '14 at 09:05
  • `localhost` aka 127.0.0.1 is how you connect from your local system to itself. Since the forwarded port is on your local system, you connect to `localhost`. – muru Dec 24 '14 at 09:06
  • Sorry but it doesn't work. Or, more probably, I am misunderstanding. I would like to connect from my pc (localhost) to my pc at work (ip_address_of_my_pc). So in a terminal I use the first command and i and end up connected (as usual) to the server company. Then what? In another terminal I should connect to myself? – Pierpaolo Dec 24 '14 at 09:16
  • @thunder1123 yes. – muru Dec 24 '14 at 09:17
  • and how to make the first step permanent? – Pierpaolo Dec 24 '14 at 09:23
  • @thunder1123 there's no way to make it *permanent*. You will need to start a connection to `server_of_the_company` some way or the other. At best, you can add a `Host` entry to [`~/.ssh/config`](http://manpages.ubuntu.com/manpages/trusty/en/man5/ssh_config.5.html) and specify `LocalForward` there. – muru Dec 24 '14 at 09:27
0

In your .ssh/config file:

Host my_pc
  ProxyCommand ssh -a server_of_the_company -W %h:%p
Roger Lipscombe
  • 407
  • 5
  • 16