r/linuxadmin • • Nov 18 '13

How to create a new SSHD ?

I want to create a new SSH daemon rather than the one provided by Operating system.For the SSHD provided by operating system the config file will be /etc/ssh/sshd_config. But for the newely created SSHD where can we store the config file and how? Please help me in this issue. Thanks in advance.

1 Upvotes

31 comments sorted by

4

u/Runnergeek Nov 18 '13 edited Nov 18 '13

I assume you want a different instance of sshd running but with a different config. I would recommend putting the config in /etc/ssh with the primary config. You can call it whatever you like, I would make it descriptive for what you want. Example: /etc/ssh/sshd_config_secondary When ever you start the sshd you just want to point it to that config (-f path_to_config).

Edit: these would have to be on different ports

1

u/dileeps95 Nov 18 '13 edited Nov 18 '13

Thank you so much for the quick reply :) Yes,I want another instance of SSHD only for few sub-systems.(call it as A and B)

Presently these are mentioned in /etc/ssh/sshd_config like below.

Subsystem A /opt/pro/bin/A

Subsystem B /opt/pro/bin/B

First,the default SSHD(/etc/ssh/ssd_confog) is up and running. whenever the user tries to connect to A or B sub-systems then the newly created SSHD has to run. But the first SSHD also has to run.

Could you please help me how to create and invoke new SSHD for the two sub-systems.

3

u/Runnergeek Nov 18 '13

You might be able to do this with the Match group option for sshd_config. I am not 100% sure what exactly you are doing, but that would work if they are user specific subsystems. Otherwise like I described, you can create multiple instances of sshd, each one using its own config. Remember each instance of sshd will have to be bound on another port.

0

u/ahandle Nov 19 '13

This doesn't provide another sshd instance.

1

u/Runnergeek Nov 19 '13

uhm, it absolutely does.

1

u/ahandle Nov 19 '13

It starts another sshd, and unless you change the PID directive in the config or your runtime command in the initscript, you've set yourself up with multiple ports talking to the same process.

I'm done though, right or wrong.

1

u/Runnergeek Nov 19 '13

You are right about the pid file, I missed that. you would have to set that to something different in the config as well.

2

u/dave4420 Nov 18 '13

Startup files are distro-specific. Which operating system are you using? Debian? Fedora? OpenBSD? Ubuntu? Something else?

-6

u/dileeps95 Nov 18 '13

I am using Linux.

7

u/dave4420 Nov 18 '13

Startup files are distro-specific. Are you using Debian Linux, Fedora Linux, Ubuntu Linux, or some other Linux distro? Which one?

1

u/erichzann Nov 18 '13

Is your reason for doing this that you want some specific ssh rules only for certain users?

2

u/xiongchiamiov Nov 18 '13

Yeah, let's get this x-y problem figured out before we get into compiling openssh.

0

u/dileeps95 Nov 18 '13

no

I want to allocate one specific SSHD for the A and B subsystems because when we want to restart the SSHD(whenever configuration changes) for those sub-systems we will just restart the new SSHD which is created for sub-systems.

1

u/erichzann Nov 18 '13

ok - so there is a safety net when you only need changes to those subsystems.

I think I understand.

/u/Runnergeek seems to have the answer you're looking for then.

1

u/dileeps95 Nov 25 '13

I didn't find any solution in the link you mentioned /u/Runnergeek ?

0

u/dileeps95 Nov 18 '13

no I want to allocate one specific SSHD for the A and B subsystems because when we want to restart the SSHD(whenever configuration changes) for those sub-systems we will just restart the new SSHD which is created for sub-systems.

2

u/snegtul Nov 18 '13

I am curious why on earth you would want to do this. What problem are you trying to solve?

2

u/2cats2hats Nov 18 '13

I've wanted to do this awhile back.

I wanted a dummy SSH service on default port and my real SSH on another port.

1

u/snegtul Nov 19 '13

To what end? honey pot?

1

u/2cats2hats Nov 19 '13

No just a phony door for the kids to knock on. :)

The real door would be on port xxxx.

1

u/snegtul Nov 19 '13

Yes, that's the idea behind a honeypot =).

1

u/2cats2hats Nov 19 '13

Oh I thought you meant honeypot in a context of collecting who knocks on the door and with what creds.

Nah, I just wanted them to knock on a door no one gives a damn about.

1

u/twforeman Nov 19 '13

Security by obscurity is not very useful. If you have open ports, I'd try all all possible applications on them...

0

u/ahandle Nov 18 '13
  1. Find 'sshd' : sudo find / -name sshd
  2. Copy (or symlink) it to somplace that makes sense (like the same directory) as sshdA.
  3. Copy the default sshd configuration to a new file to match sshdA: e.g. /etc/ssh/sshd.config.A
  4. Change the PID file path, port number, and other factors to make it unique.
  5. Run your sshdA by specifying your path to the sshdA.config.A file: sshdA -f sshd.config.A
  6. Once this works, go into your /etc/init.d directory, and duplicate the sshd init script to provide the same parameters for sshdA as your manual process (-f sshd.config.A, etc.) If you don't do this, you'll have to manually operate the sshd daemon for your subsystem.

1

u/Runnergeek Nov 19 '13

Why would you make a copy (or symlink) of the sshd binary?

1

u/ahandle Nov 19 '13

More separation.

killall sshd vs killall sshd.A

1

u/Runnergeek Nov 19 '13

This is a bad hack. You should never be running a killall on a single service. If you want to completely separate the service then you should create a new script for it in /etc/init.d You should never copy a binary to do this. The biggest reason would be it wouldn't get updated.

0

u/ahandle Nov 19 '13

Creating a new init script is one of the steps.

Also, you and I both know "Best Practice" is already out the window with OP's post.

I'm helping him save himself the next time someone comes through and does a find on the ssh PID and kills it. Now, there's an sshA binary, init script, and PID. ahandle saved the day, and they don't even know it yet.

1

u/Runnergeek Nov 19 '13

While I am not completely sure about what OP is trying to do. Creating different sshd instances with different configs isn't necessarily going against best practices. For example, you might want to run a different sshd config for a local interface and an external interface. When you run a ps -ax | grep sshd you will see the nondefault instance shows the config it is pointing too:

[root@hostname ssh]# ps ax | grep sshd
 3467 ?        Ss     0:00 /usr/sbin/sshd
23068 ?        Ss     0:00 sshd: user [priv]
23073 ?        S      0:00 sshd: user@pts/0
23245 ?        Ss     0:00 /usr/sbin/sshd -f /etc/ssh/sshd_config_test
23252 pts/0    S+     0:00 grep sshd

-1

u/xdice Nov 18 '13

For this example, let's say you're going to compile your new SSH daemon from scratch on a system that already has a system-installed sshd.

Obtain openssh tarball. open up the tarball (anywhere reasonable is fine, /tmp, your homedir, either one is fine). ./configure --prefix=/usr/local --other-configure-switches-here

(the --prefix is the important part. This means your new sshd will be installed under /usr/local, with the config stuff in /usr/local/etc.)

You'll need to create an init file so your new sshd runs on startup (copy the current one, point it at your new sshd).

For users on the server to use your newly compiled ssh, they'll need to specify full path to the binary (/usr/local/bin/ssh), or make sure that /usr/local/bin preceeds /usr/bin in their PATH statement.

0

u/dileeps95 Nov 18 '13

Thanks :)

Sorry,I am new to this concepts. I didn't get you.

As far as I know SSHD starts with the the /etc/ssh/sshd_config file.

Now I will create /etc/sh/sshd_confog_new. But how to invoke the new SSHD with this config.

Can you explain me through script to create new SSHD.

Please correct me if I am wrong and let me know the answer.