You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
step 2:
start sshd server
sudo /etc/init.d/ssh start
step 3:
connected to sshd server from xshell (a powerful terminal emulator which better than windows cmd line).
if you don't have xshell , use putty or any other client instead
step 4:
closed the bash cmd window , xshell connection is also closed.
Question:
how do I run sshd as a windows service ?
thanks !
Reacted by Joel Moberg, Ihor Levchenko, Mark Penner, László Király, Edwin Hui, Josh, juhntao, George Hahn, Lei Zhang, Bradford and 11 more
I would suggest instead running urxvt in xming, because sshd needs to be run as root, and there are annoying problems that can arise with that.
Right now there is no support for running daemons as windows services because WSL is meant for developer workstations rather than servers, although some unprivileged daemons (like urxvtd) can be run silently with a little bit of workaround.
That is not even remotely accurate. There are no annoying problems with running sshd as root (sudo service ssh start); and even if there were, you can run sshd on an unprivileged port no different than urxvtd. For people uninterested in inviting all of X11 to the party, PuTTY and a dozen other SSH clients are lighter weight and make more sense. I use the Chrome Secure Shell Extension. Indeed, X clients have been explicitly identified as low priority for the WSL project, but do run, happily, as a side effect of coincidental socket and pty improvements.
Reacted by Forrest Hopkins, Jesús Gómez, Michael De Roover and mikesm
Yeah, but I run urxvtd on startup with run.exe, whereas to start the sshd service you have to type a p/w (because you are sudoing it "superuser do", i.e. running it as the root user). I have a shortcut that does
run.exe bash.exe -c "urxvtd -q -o -f ; bash"
in the startup folder for my Windows user (in addition to running Xming on startup), so I can launch urxvtc whenever I want, with the daemon running totally silently with bash.exe -c urxvtc
I'm not saying you can't run sshd, just that you can't do it silently so it "appears like" a Windows service, and the reason why is that you have to type in your sudo password.
Sure, I guess you could get around this maybe with some kind of batch file that types in your sudo password?
Make sure you have the syntax right? Test it on an actual Ubuntu machine if you have one available; the sudoers file format can be finicky to get right.
(Disclaimer: I haven't actually tried this particular command. I've run other commands with passwordless sudo under WSL, though.
therealkencAdam Seering (@aseering), David Manouchehri (@Manouchehri) says in the cmake thread that you also need to star the sshd service in a bash.exe terminal that also has Windows admin credentials in order to open up a socket for sshd. Have you guys found a way around that?
fpqc -- could you run on a higher port? The problem is that the default sshd port is in the system-port range, as David Manouchehri (@Manouchehri) said. I often bind servers to port 2222, or some other higher-numbered port, to work around that limitation.
fpqc, I'm not running WSL in terminal with Windows admin privileges. It binds to 22 fine with sudo service ssh start or however you feel like starting the daemon. You can also start it on 2222 like Adam Seering (@aseering) says, but there's a minor issue with perms on /dev/tty so you still have to run it as root.
therealkenc It seems to work for me too doing that, but I have a problem connecting to it with PuTTY, and if I open another terminal and try to connect it appears to connect but then dies.
fpqc@FPQC-PC:~|⇒ ssh -vvv 127.0.0.1
OpenSSH_6.6.1, OpenSSL 1.0.1f 6 Jan 2014
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug2: ssh_connect: needpriv 0
debug1: Connecting to 127.0.0.1 [127.0.0.1] port 22.
debug1: Connection established.
debug3: Incorrect RSA1 identifier
debug3: Could not load "/home/fpqc/.ssh/id_rsa" as a RSA1 public key
debug1: identity file /home/fpqc/.ssh/id_rsa type 1
debug1: identity file /home/fpqc/.ssh/id_rsa-cert type -1
debug1: identity file /home/fpqc/.ssh/id_dsa type -1
debug1: identity file /home/fpqc/.ssh/id_dsa-cert type -1
debug1: identity file /home/fpqc/.ssh/id_ecdsa type -1
debug1: identity file /home/fpqc/.ssh/id_ecdsa-cert type -1
debug1: identity file /home/fpqc/.ssh/id_ed25519 type -1
debug1: identity file /home/fpqc/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.7
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.7
debug1: match: OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.7 pat OpenSSH_6.6.1* compat 0x04000000
debug2: fd 3 setting O_NONBLOCK
debug3: load_hostkeys: loading entries for host "127.0.0.1" from file "/home/fpqc/.ssh/known_hosts"
debug3: load_hostkeys: loaded 0 keys
debug1: SSH2_MSG_KEXINIT sent
Connection closed by 127.0.0.1
When I follow kabinpokhrel's steps, I am not able to login into my computer it always give me
"Permission denied, please try again." Even though I am 100% sure that the passowrd is correct, I created new Users and it still did not work. What is the reason for this?
@Luindil - sounds like something odd is going on. You can try ssh -v -p [portnumber] [username]@localhost from a different bash.exe window to see more info, maybe it will tell you at what point it is failing. (Spelling everything out on the command line helps check assumptions, and -v adds information that might be helpful.)
To confirm the password, you could try su - [username] which will ask for the password, unless you are root. Or, it should be asking for the password when you use sudo (until you added the NOPASSWD: setting with visudo). (You do know it is not necessarily the password you use to log in to Windows, right?) To reset the password, you can use lxrun /setdefaultuser root before logging in, then the passwd command, then /setdefaultuser back again. Or set up public keys and authenticate that way.
If the permission denied error is from something else, e.g. a file permission, knowing which file, might make solving the issue easier, though if you used sudo to start it that shouldn't be a problem.
If you don't get enough information with ssh -v, or from up to three of the -v's, you might need to look into ways to get sshd to put its log somewhere useful, like see if it puts its log to stdout if you run sshd in the foreground. I've still not gotten syslog (or systemd's journal) working...
The service command isn't really supported completely (currently), so you could bypass that and just run the bash script sudo /etc/init.d/ssh {start|stop|restart}. Service usually works to start that bash script, but by going directly to the script you bypass one possible source of errors. You could also make a copy of the script and add command line options (e.g. logging?) to troubleshoot.
@Luindil Make sure you disable the SSH related Windows Services that appear to be installed by default (namely, SSH Broker and SSH Proxy). Another option is to switch port.
Thank you both for answering, I just figured out that it is because the port is already used by windows. When I use e.g. 23 as a port it works like a charm. Chris Wilson (@qris) already mentioned it in an above post.
Gentlemen, We have for years been running sshd under cygwin. We use a cygrunserv process that runs as local administrator and map all registry settings. Cant we just get a local admin that starts the cron scheduler/services.
Reacted by Thomas Hackett, Grégory Pakosz, syffs, Jan Christoph Uhde and Jin Jung
fenchu not yet. since distros are installed at the user rather than computer level, running as local admin will work weird. Running as your own user but with local admin permission could work but comes with its own problems.
Activity
fpqc commentedon Jul 1, 2016
I would suggest instead running urxvt in xming, because sshd needs to be run as root, and there are annoying problems that can arise with that.
Right now there is no support for running daemons as windows services because WSL is meant for developer workstations rather than servers, although some unprivileged daemons (like urxvtd) can be run silently with a little bit of workaround.
therealkenc commentedon Jul 1, 2016
That is not even remotely accurate. There are no annoying problems with running sshd as root (
sudo service ssh start); and even if there were, you can run sshd on an unprivileged port no different than urxvtd. For people uninterested in inviting all of X11 to the party, PuTTY and a dozen other SSH clients are lighter weight and make more sense. I use the Chrome Secure Shell Extension. Indeed, X clients have been explicitly identified as low priority for the WSL project, but do run, happily, as a side effect of coincidental socket and pty improvements.fpqc commentedon Jul 2, 2016
Yeah, but I run urxvtd on startup with run.exe, whereas to start the sshd service you have to type a p/w (because you are sudoing it "superuser do", i.e. running it as the root user). I have a shortcut that does
run.exe bash.exe -c "urxvtd -q -o -f ; bash"in the startup folder for my Windows user (in addition to running Xming on startup), so I can launch urxvtc whenever I want, with the daemon running totally silently with
bash.exe -c urxvtcI'm not saying you can't run sshd, just that you can't do it silently so it "appears like" a Windows service, and the reason why is that you have to type in your sudo password.
Sure, I guess you could get around this maybe with some kind of batch file that types in your sudo password?
aseering commentedon Jul 2, 2016
Or you could modify your sudoers file to not require a password for that command.
fpqc commentedon Jul 2, 2016
Yeah, that works too! Good idea!
Edit: How did you do it? I set NOPASSWD mode for /bin/service and it still asks me for a pw.
aseering commentedon Jul 2, 2016
Make sure you have the syntax right? Test it on an actual Ubuntu machine if you have one available; the sudoers file format can be finicky to get right.
(Disclaimer: I haven't actually tried this particular command. I've run other commands with passwordless sudo under WSL, though.
fpqc commentedon Jul 3, 2016
therealkenc Adam Seering (@aseering), David Manouchehri (@Manouchehri) says in the cmake thread that you also need to star the sshd service in a bash.exe terminal that also has Windows admin credentials in order to open up a socket for sshd. Have you guys found a way around that?
Manouchehri commentedon Jul 3, 2016
Can a normal user can ever bind on a system port on Windows?
fpqc commentedon Jul 3, 2016
David Manouchehri (@Manouchehri) I think so. Bittorrent clients can, and they can even make UPnP requests, I think.
Manouchehri commentedon Jul 3, 2016
BitTorrent (shouldn't) run on system ports (0-1024). Most clients bind on a UDP port in the dynamic port range.
aseering commentedon Jul 3, 2016
fpqc -- could you run on a higher port? The problem is that the default sshd port is in the system-port range, as David Manouchehri (@Manouchehri) said. I often bind servers to port 2222, or some other higher-numbered port, to work around that limitation.
therealkenc commentedon Jul 3, 2016
fpqc, I'm not running WSL in terminal with Windows admin privileges. It binds to 22 fine with
sudo service ssh startor however you feel like starting the daemon. You can also start it on 2222 like Adam Seering (@aseering) says, but there's a minor issue with perms on /dev/tty so you still have to run it as root.Manouchehri commentedon Jul 3, 2016
therealkenc Permission issues on the Windows or Linux side?
/dev/ttyshows as owned by the user to me.ubuntu@DESKTOP-3RQO5S5:~$ ls -l /dev/tty crw------- 1 ubuntu tty 4, 1 Jul 2 22:23 /dev/ttyfpqc commentedon Jul 3, 2016
therealkenc It seems to work for me too doing that, but I have a problem connecting to it with PuTTY, and if I open another terminal and try to connect it appears to connect but then dies.
Manouchehri commentedon Jul 3, 2016
Looks like we actually can bind to 22/TCP without Windows admin privs?
61 remaining items
gdh1995 commentedon Nov 13, 2016
fpqc you are right.
Oh my god, the single
sshdprocess exits at once if I exit bash.exe.fpqc commentedon Nov 13, 2016
Dahan Gong (@gdh1995) Yeah, that was always the problem. I didn't even know about the sshd -D thing.
CPrescher commentedon Dec 1, 2016
When I follow kabinpokhrel's steps, I am not able to login into my computer it always give me
"Permission denied, please try again." Even though I am 100% sure that the passowrd is correct, I created new Users and it still did not work. What is the reason for this?
rodrymbo commentedon Dec 1, 2016
@Luindil - sounds like something odd is going on. You can try
ssh -v -p [portnumber] [username]@localhostfrom a different bash.exe window to see more info, maybe it will tell you at what point it is failing. (Spelling everything out on the command line helps check assumptions, and -v adds information that might be helpful.)To confirm the password, you could try
su - [username]which will ask for the password, unless you are root. Or, it should be asking for the password when you use sudo (until you added the NOPASSWD: setting with visudo). (You do know it is not necessarily the password you use to log in to Windows, right?) To reset the password, you can uselxrun /setdefaultuser rootbefore logging in, then thepasswdcommand, then /setdefaultuser back again. Or set up public keys and authenticate that way.If the permission denied error is from something else, e.g. a file permission, knowing which file, might make solving the issue easier, though if you used
sudoto start it that shouldn't be a problem.If you don't get enough information with ssh -v, or from up to three of the -v's, you might need to look into ways to get sshd to put its log somewhere useful, like see if it puts its log to stdout if you run sshd in the foreground. I've still not gotten syslog (or systemd's journal) working...
The
servicecommand isn't really supported completely (currently), so you could bypass that and just run the bash scriptsudo /etc/init.d/ssh {start|stop|restart}.Serviceusually works to start that bash script, but by going directly to the script you bypass one possible source of errors. You could also make a copy of the script and add command line options (e.g. logging?) to troubleshoot.lypanov commentedon Dec 7, 2016
@Luindil Make sure you disable the SSH related Windows Services that appear to be installed by default (namely, SSH Broker and SSH Proxy). Another option is to switch port.
CPrescher commentedon Dec 7, 2016
Thank you both for answering, I just figured out that it is because the port is already used by windows. When I use e.g. 23 as a port it works like a charm. Chris Wilson (@qris) already mentioned it in an above post.
fpqc commentedon Dec 7, 2016
@luindil isn't port 23 something super important like smtp?
aseering commentedon Jan 4, 2017
Sys-worX.net (@sysworx) -- there's more discussion of this approach here: https://wsl-forum.qztc.io/viewtopic.php?f=6&t=10 . Read through the comments; in particular, if you have a command that exits immediately, you have to somehow artificially add another command that doesn't exit immediately.
repalash commentedon Sep 28, 2017
I also had to enable the ssh port in Windows Firewall for all incoming connections to allow remote logins.
rickywu commentedon Nov 14, 2017
Hi all,
I found this tool is very useful and can run ssh server without any window in background
https://github.com/131/dispatcher
fenchu commentedon Dec 5, 2017
Gentlemen, We have for years been running sshd under cygwin. We use a cygrunserv process that runs as local administrator and map all registry settings. Cant we just get a local admin that starts the cron scheduler/services.
fpqc commentedon Dec 6, 2017
fenchu not yet. since distros are installed at the user rather than computer level, running as local admin will work weird. Running as your own user but with local admin permission could work but comes with its own problems.
therealkenc commentedon May 24, 2018
sshdand other processes not attached to a tty now persist in WSL as of April Update.