I would like to use ssh to access the shell of another Ubuntu computer and issue a few commands. I'm interested in how to form the shh command in the following scenarios. To keep it simple, I will not be using password protected accounts. I would like to focus primarily on command formations that establish the connection.
- Two local Ubuntu computers directly connected with an Ethernet cable:
- Two remote Ubuntu computers where each is connected via cable modem (each has it's own ip):
- Same as previous, but one is using NAT:
- Two remote Ubuntu computers, where one is connected via a cable modem and the other is connected via a wireless router:
- Two local boxes connected to the same wireless router:
With local Ubuntu boxes, whether they're connected directly or using a switch, you can use hostname.local to connect. So, if your laptop is called bambuntulaptop, then you can connect to it using bambuntulaptop.local.
For non-local connections, you'll have to use an IP address or setup a dns server. You can use
ddclient coupled with a service like dyndns.org.
NAT isn't really relevant with regards to ssh. You'll need to forward port 22 to the right machine, or configure your ssh server to use another port and forward that one. Port 22 is the default ssh port.
You must not allow non-protected accounts. There are thousands, or hundreds of thousands of computers who are scanning for things to abuse. Allowing any user on the internet to run programs on your computer is a seriously bad idea. Ubuntu is secure, but not that secure. In fact, I don't think you will be allowed to use non-password protected accounts with ssh. If you wanted to do that, then you'd need to setup keys. That would be another question.
The command to establish the connection itself, could hardly be any easier:
ssh [email protected]. In other words, reusing the example from above;
ssh [email protected].
ssh works the same way across all these scenarios. The network configuration is not important. ( OK You may have to set up port mapping to go across a NAT ).
At it's simplest you run
Not using passwords doesn't make it simpler, because you will have to set up keys, which is slightly more complicated.
Setting up ssh is simple to do, just install openssh-server and openssh-client and then connect using