TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

SSH as a Sudo Replacement

230 pointsby legobeet11 months ago

19 comments

kelnos11 months ago
My main objection to this is just the added complexity. Instead of a single suid binary that reads a config file and calls exec(), now you have one binary that runs as root and listens on a UNIX socket, and another that talks to a UNIX socket; both of them have to do asymmetric crypto stuff.<p>It seems like the main argument against sudo&#x2F;doas being presented is that you have a suid binary accessible to any user, and if there&#x27;s a bug in it, an unauthorized user might be able to use it for privilege escalation. If that&#x27;s really the main issue, then you can:<p><pre><code> chgrp wheel &#x2F;usr&#x2F;bin&#x2F;sudo chmod o-rwx &#x2F;usr&#x2F;bin&#x2F;sudo </code></pre> Add any sudoers to the wheel group, and there you go: only users that can sudo are allowed to even read the bytes of the file off disk, let alone execute them. This essentially gives you the same access-related security as the sshd approach (the UNIX socket there is set up to be only accessible to users in wheel), with much much much less complexity.<p>And since the sshd approach doesn&#x27;t allow you to restrict root access to only certain commands (like sudo does), even if there is a bug in sudo that allows a user to bypass the command restrictions, that still gives no more access than the sshd approach.<p>If you are worried about your system package manager messing up the permissions on &#x2F;usr&#x2F;bin&#x2F;sudo, you can put something in cron to fix them up that runs every hour or whatever you&#x27;re comfortable with. Or you can uninstall sudo entirely, and manually install it from source to some other location. Then you have to maintain and upgrade it, manually, of course, unfortunately.
评论 #40766221 未加载
评论 #40764929 未加载
评论 #40765351 未加载
评论 #40765030 未加载
评论 #40765588 未加载
评论 #40767922 未加载
评论 #40765195 未加载
wooptoo11 months ago
Isn&#x27;t this what systemd run0 is now doing?<p><pre><code> There&#x27;s a new tool in systemd, called &quot;run0&quot;. Or actually, it&#x27;s not a new tool, it&#x27;s actually the long existing tool &quot;systemd-run&quot;, but when invoked under the &quot;run0&quot; name (via a symlink) it behaves a lot like a sudo clone. But with one key difference: it&#x27;s *not* in fact SUID. Instead it just asks the service manager to invoke a command or shell under the target user&#x27;s UID. It allocates a new PTY for that, and then shovels data back and forth from the originating TTY and this PTY. Or in other words: the target command is invoked in an isolated exec context, freshly forked off PID 1, without inheriting any context from the client (well, admittedly, we *do* propagate $TERM, but that&#x27;s an explicit exception, i.e. allowlist rather than denylist). One could say, &quot;run0&quot; is closer to behaviour of &quot;ssh&quot; than to &quot;sudo&quot;, in many ways. </code></pre> - <a href="https:&#x2F;&#x2F;mastodon.social&#x2F;@pid_eins&#x2F;112353324518585654" rel="nofollow">https:&#x2F;&#x2F;mastodon.social&#x2F;@pid_eins&#x2F;112353324518585654</a>
评论 #40777055 未加载
aaaronic11 months ago
Am I missing something?<p>How is logging into ssh (sshd) AS root more secure than using sudo? I honestly don’t even know how dangerous that is because I’ve always been told to never allow it. I see here thought goes into preventing that for a remote user, so I’m not talking about that aspect of security here.<p>Maybe it has to do with #3 in the sudo limitations — I certainly don’t see any benefits vis-a-vis #1.<p>I totally get that this is an experiment, but I suspect it is more vulnerable than using sudo, not less (the open socket proxy looks interestingly vulnerable to a man in the middle attack).<p>Having said all that, I did learn some tricks old tools are capable of, so kudos for showing me something new.
评论 #40763746 未加载
评论 #40763576 未加载
评论 #40766437 未加载
评论 #40766296 未加载
评论 #40763767 未加载
评论 #40766955 未加载
cycomanic11 months ago
So what happens if ssh (IIRC correctly in typical configurations it depends on network to start) fails to start at boot? You can&#x27;t even login at failsave console. What does this actually buy us over sudo or su? Sure you avoid a setuid binary but instead you are now running a network service (even though only connected to a socket) with root priveledges.
评论 #40764442 未加载
评论 #40764388 未加载
评论 #40764356 未加载
评论 #40764996 未加载
iroddis11 months ago
I think it’s a bit remiss to not include all of the downsides of this approach. sudo allows control over which groups can exercise which commands, what args those commands accept, subshell spawns, etc, etc, etc.<p>This approach loses a lot of this fine-grained control, and also relies on trusted keys, which are harder to manage than editing a sudoers file.<p>To see all the amazing things that sudo can do, I’d really recommend the Sudo Mastery book.
评论 #40763555 未加载
hernantz11 months ago
This is a similar idea to run0 by Systemd: <a href="https:&#x2F;&#x2F;news.itsfoss.com&#x2F;systemd-run0&#x2F;" rel="nofollow">https:&#x2F;&#x2F;news.itsfoss.com&#x2F;systemd-run0&#x2F;</a>
评论 #40768788 未加载
the847211 months ago
One of the issues with ssh is that spawning processes isn&#x27;t part of the protocol. And it&#x27;s a remote protocol, so it can&#x27;t pass local resources to the child. So you can&#x27;t pass a null-separated array of arguments, pass extra file descriptors or specify an executable. Instead it just passes a string to a server-configured shell. So you need to shell-escape things and know which shell is running on the server side.<p>To use SSH as a proper sudo replacement it&#x27;d need something closer to posix_spawn as an extension.
评论 #40769040 未加载
TacticalCoder11 months ago
100 000 times yes: I do something similar and I described that here on HN in a comment &#x2F; comments in the past!<p>The way I do is a bit different...<p>I&#x27;m using a dedicated machine as my physical &quot;SSH console&quot; and that machine is living on a private LAN which is separated from the rest of the machines at home. It&#x27;s on an unmanaged switch, using ethernet cables (but no trunk).<p>Then the only way to login is using SSH but, here&#x27;s a little spin... <i>with a Yubikey</i>.<p>The desktop PC has its own firewall, only accepting SSH traffic in from the IP &#x2F; MAC address of my &quot;SSH console&quot; (on the private LAN it&#x27;s sharing with the SSH console... On the other physical LAN, my desktop can access the Internet).<p>Then the <i>sshd</i> daemon is configured to only allow pub&#x2F;priv key logins, no password logins.<p>So basically when I need root, I boot up my &quot;SSH console&quot; (which boots ultra quickly for there&#x27;s basically nothing on that machine), log in, hit the up arrow to get back the &quot;ssh root@...&quot; line, hit enter, press the Yubikey.<p>That &quot;ssh console&quot; and its keyboard is on my desk, always withing reaching distance.<p>iptables&#x2F;nftables (on a private LAN moreover, physically separated from the other private LAN) + sshd: you judge if this is more or less secure than sudo binaries &#x2F; su.<p>As to the &quot;why&quot;, I&#x27;d answer &quot;because I can&quot;. I did set that up such a long time ago that I don&#x27;t even remember when I did. I think I started toying with that idea two years ago and I&#x27;ve been using it ever since. Zero problem. Not a single issue.
评论 #40764817 未加载
mise_en_place11 months ago
This is an elegant solution to the problem. We don&#x27;t need to treat users as children, but at the same time we should avoid potential foot guns with sensible defaults. I&#x27;d argue that even `su` is not needed, if you need to be root, then login as root via console. This is as close as possible to logging into root from the console tty.
评论 #40764192 未加载
kccqzy11 months ago
I did something similar a decade ago (well without the UNIX socket bit, but just a separate sshd listening on localhost only and also no need to deal with SCM_RIGHTS). Nothing good or bad came out of it. I simply got bored and didn&#x27;t bother porting this setup to the next machine.
coretx11 months ago
This is not a solution, it&#x27;s a workaround. One that breaks with ( outdated ) system design doctrines and therefore is likely to spawn more cans of worms and will certainly increase the amount of technical debt at present.
dheera11 months ago
&gt; I changed the root password<p>If you&#x27;re going to set a root password, you might as well just do this and if I&#x27;m not mistaken it accomplishes everything you want<p><pre><code> alias sudo=&quot;su -c&quot;</code></pre>
评论 #40775032 未加载
tankenmate11 months ago
One issue I see with this is Single User Mode (aka recovery mode in grub (or similar) boot loader). Now you can&#x27;t login as root to recover from init (systemd) configuration issues without having alternate boot media to get you access. I know it might sound pedantic but I used just this feature two days ago while upgrading a machine to a newer Linux release (the upgrade introduced an issue with the systemd &#x2F; netplan config that got systemd into a loop due to deprecated keywords in the netplan config).
评论 #40766734 未加载
gnuser11 months ago
Good stuff. Imagine this though: ssh as user access control using a multiuser system such as gnu&#x2F;linux<p>byw everyone should be using ed25519 or at least 2048+
xfitm311 months ago
Fixing things that aren&#x27;t broken. Changing things just because they can be changed. Sometimes boring and stagnant is good.
评论 #40766447 未加载
didntcheck11 months ago
I&#x27;ve used ssh to localhost as a hack for a backup-to-external-drive script (using Borg iirc) where I wanted the source reading and backup writing to be done as different users. There may have been a more elegant solution but it worked well enough
ketily11 months ago
This reminds me a little of plam 9 and inferno in treating local resources and network resources with a uniform protocol
YesThatTom211 months ago
Usenix LISA (now called SRECon) had a paper about this technique in 2004:<p><a href="https:&#x2F;&#x2F;www.usenix.org&#x2F;legacy&#x2F;publications&#x2F;library&#x2F;proceedings&#x2F;lisa04&#x2F;tech&#x2F;napier.html" rel="nofollow">https:&#x2F;&#x2F;www.usenix.org&#x2F;legacy&#x2F;publications&#x2F;library&#x2F;proceedin...</a><p>Those who ignore Usenix are doomed to repeat it … 20 years later.
RecycledEle11 months ago
It seems like a way for Fed.Gov to know everything we do on our computers.<p>Kill it with fire.
评论 #40764738 未加载