How to connect with sshd? - telnet

I need to connect my laptop (Mac OS) to my Virtual Box (Debian) via sshd and then test telnet in Debian. Problem is I can't seem to connect via sshd.
I get
sshd re-exec requires execution with an absolute path
when I run
sshd root#192.xxx.xx.xx
But if I use an absolute path as suggested I get this instead:
/usr/sbin/sshd root#192.xxx.xx.xxx
Extra argument root#192.xxx.xx.xxx
What is the problem and how does one connect via sshd?

sshd is the dæmon program that listens to SSH port, then let incoming connections in.
You want to use ssh (without "d") as a client to connect to a remote machine:
usr/sbin/ssh root#192.xxx.xx.xxx

Related

Can't connect to port 22, Connection timed out

I just recently got into whatever you might call this stuff. I was just trying to send a java file over to the computer I ssh to. But when I went to do it, I just get told
sh: connect to host port 22: Connection timed out
lost connection
If possible I would like it explained very simply because of how new I am to this kind of stuff.
SSH to remote host(VM Ubuntu) from VS code terminal
Install VS Code with Remote Development extension pack.
Install Virtual machine (Virtual box) and Ubuntu running on it.
Check Ubuntu-Network-Settings-IPv4 address (10.0.2.15-default for VM).
Go to your virtual box Settings-Network-NAT Adapter (double-check).
Go to your virtual box Settings-Network-In Advanced-Port Forwarding.
Add this as given below and click ok and hereafter consider 127.0.1.1 for ssh.
portforwardinginVM
View the status and disable firewall settings in Ubuntu VM (ufw command).
In VS Code, View-Command Palette- Add new SSH host .
Add ssh username#127.0.1.1 and enter.
Or go to the terminal window (eg. Powershell) and type ssh username#127.0.1.1, it will ask if you want to update to host lists permanently, asking like yes/no and also your Ubuntu password to confirm.
Now try to connect to the host using username#127.0.1.1 and selecting OS like Ubuntu, then type the Ubuntu password.
That's it you are logged in to your virtual machine and can access files now from your local machine.

SSH server and localhost

I tried to install a SSH server on WSL, it never worked. So i installed my SSH server on my laptop and i try to connect, it doesn't work either. But it works from my phone on 4G or everything expect my computer on local
I get this error everytime, either with WSL Debian ou Windows :
ssh: connect to host localhost port 22: Connection refused
Check first this OpenSSH Windows installation guide:
It includes a network configuration:
Allow incoming connections to SSH server in Windows Firewall:
When installed as an optional feature, the firewall rule “OpenSSH SSH Server (sshd)” should have been created automatically.
If not, proceed to create and enable the rule as follows.
Either run the following PowerShell command as the Administrator:
New-NetFirewallRule -Name sshd -DisplayName 'OpenSSH SSH Server' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22 -Program "C:\System32\OpenSSH\sshd.exe"
Replace C:\System32\OpenSSH\sshd.exe with the actual path to the sshd.exe (C:\Program Files\OpenSSH\ssh.exe, had you followed the manual installation instructions above).
or go to Control Panel > System and Security > Windows Firewall1 > Advanced Settings > Inbound Rules and add a new rule for port 22.
Then you can check if at least your SSH daemon can receive anything.
The OP SRP adds in the discussion:
The problem turned out to be other machine with same IP address as the server."
I cheated and it works: I used a VPN.

can't access apache on docker from my localhost

I've been following this tutorial for beginners about docker which basically instructs you to create an apache container and map a localhost port to the one on the container.
when I try localhost:80 it doesn't connect, although the container is up and running.
I even made a rule in the firewall to allow connection to port 80, but couldn't get connected to the localhost.
Any ideas ?
On Windows/OS X, Docker is running inside a Linux virtual machine (Docker Toolbox) with a default IP address of 192.168.99.100. Thus, when you use docker run -p 80:80 to bind the container port to host port, it in fact binds to the virtual machine's port 80. Thus the address you need is http://192.168.99.100.
The 172.17.0.3 address is the address of the docker container inside that virtual machine, and is not accessible directly from Windows/OS X.
Add a line to your DockerFile before restarting apache.
RUN echo 'ServerName localhost' >> /etc/apache2/apache2.conf
I stumbled upon this question as I was looking for a way to bind my local HTTP port (80) to the HTTP port of my container, an Apache container running on Docker Desktop for Windows - through WSL2 (this is important)
I couldn't find a quick and easy way to do this, so I figured it out myself.
What you must do is bind your local port (on Windows) to the port on WSL.
Here is how I did it :
$wsl_ip = (wsl -d "docker-desktop" -- "ifconfig" "eth0" "|" "grep" "inet addr:").trim("").split(":").split()[2]
netsh interface portproxy add v4tov4 listenport=443 listenaddress=0.0.0.0 connectport=443 connectaddress=$wsl_ip
netsh interface portproxy add v4tov4 listenport=80 listenaddress=0.0.0.0 connectport=80 connectaddress=$wsl_ip
You can either create a Powershell Script (.ps1) and run it with Powershell, or copy/paste each command line into Windows Terminal / Powershell running with Administrator Privileges.
What this does is :
attach to the "docker-desktop" distribution running in WSL2 2
run "ifconfig eth0 | grep inet addr:" to get the local IP address of
the "virtual machine"
parse the result, and use Netsh to
create a portproxy between port 80 of your Windows machine and port
80 of your Linux machine. Same is done for port 443. You can easily
map other ports if you understand what the command is doing.
More explanation :
Since Docker for Windows 10/11 uses WSL2, when you expose a port (through docker-compose or with an EXPOSE command in your Dockerfile), it is exposed to a Linux Distribution called "docker-desktop" that is ran with WSL2. For some reason, ports 80 and 443 that are exposed from a container are NOT forwarded to the host.
The official documentation acknoledges some issues but their solution is just to use another port (for example, 8080 mapped to 80).
Issues with this method :
Each time you reboot your system (or WSL2), the Linux machine gets assigned a new IP and you have to do it again. What you could do is setup a command to run when your container starts that connects through ssh to the host and runs the script, but I'm too lazy to have done it myself.

Docker to run X applications while connected through SSH

I have used these instructions for Running Gui Apps with Docker to create images that allow me to launch GUI based applications.
It all works flawlessly when running Docker on the same machine, but it stops working when running it on a remote host.
Locally, I can run
docker --rm --ti -e DISPLAY -e <X tmp> <image_name> xclock
And I can get xclock running on my host machine.
When connecting remotely to a host with XForwarding, I am able to run X applications that show up on my local X Server, as anyone would expect.
However if in the remote host I try to run the above docker command, it fails to connect to the DISPLAY (usually localhost:10.0)
I think the problem is that the XForwarding is setup on the localhost interface of the remote host.
So the docker host has no way to connect to DISPLAY=localhost:10.0 because that localhost means the remote host, unreachable from docker itself.
Can anyone suggest an elegant way to solve this?
Regards
Alessandro
EDIT1:
One possible way I guess is to use socat to forward the remote /tmp/.X11-unix to the local machine. This way I would not need to use port forwarding.
It also looks like openssh 6.7 will natively support unix socket forwarding.
When running X applications through SSH (ssh -X), you are not using the /tmp/.X11-unix socket to communicate with the X server. You are rather using a tunnel through SSH reached via "localhost:10.0".
In order to get this to work, you need to make sure the SSH server supports X connections to the external address by setting
X11UseLocalhost no
in /etc/ssh/sshd_config.
Then $DISPLAY inside the container should be set to the IP address of the Docker host computer on the docker interface - typically 172.17.0.1. So $DISPLAY will then be 172.17.0.1:10
You need to add the X authentication token inside the docker container with "xauth add" (see here)
If there is any firewall on the Docker host computer, you will have to open up the TCP ports related to this tunnel. Typically you will have to run something like
ufw allow from 172.17.0.0/16 to any port $TCPPORT proto tcp
if you use ufw.
Then it should work. I hope it helps. See also my other answer here https://stackoverflow.com/a/48235281/5744809 for more details.

could not resolve hostname with scp

I am accessing an ubuntu server over ssh with putty on my windows machine and trying to download a single file to my local windows machine
my windows username is Mark and my hostname per cmd is Marks I am trying the following command on the remote server
scp backup.sql mark#marks:desktop
and I get could not resolve hostname I have tried to put in what I think myip address is and the connection times out
The syntax is this, relative to where you're issuing the command:
scp user#host_from:location/file user#host_to:location/file
And of course if you're local you can omit the user#host prefixes:
scp local_file me#host_to:~/local_file
The direction is always from > to relative to where you issue the command.
binarysubstrate is right about the syntax. The problem is, if the OP puts the name (or address) of his windows client in the 'to' part of the scp command, it probably won't work for a number of reasons:
his windows machine may not have a resolvable FQDN,
his windows machine may be behind a NAT firewall that is not setup to port-forward SSH requests,
he probably does not have an SSH daemon running on his windows machine.
To simply copy a file from the remote server down to a windows client, I would recommend WinSCP.
From the ser you ping your machine name ? Try replace machine name for the IP Address, or add your machine name to hosts configuration file from the server.