Remix.run Logo
Disable Your SSH access accidentally with scp(sny.sh)
60 points by zdw 4 days ago | 18 comments
chasil an hour ago | parent | next [-]

I have a few observations about this article.

Generally, try not to use SCP. It has been a crufty old program from the Berkeley R-Utilities, but newer OpenSSH releases have rewritten it to use the sftp-server server instead. There will be wildly different behavior between these implementations.

The backend SCP changes are documented here:

https://lwn.net/Articles/835962/

If you need something that SFTP cannot do, then use tar on both sides.

PuTTY has implemented their pscp to prefer the sftp-server for many years, in a long prediction of the eventual abandonment. Their pscp implementation is a better drop-in replacement than the OpenSSH solutions.

The allure of SCP is retry on failure, which is somewhat more difficult with SFTP:

  until scp source.txt user@target:dir/
  do echo target down; sleep 300
  done
Converting that to pscp is much easier than SFTP.

I also have an older rhel5 system where I am running tinysshd to use better SSH crypto. Due to upgrades, NFS is now squashing everything to nobody, so I had to disable precisely these checks to let users login with their authorized_keys. I can post the code if anybody is curious.

mistrial9 an hour ago | parent [-]

you sound so wise and produce excellent reference, but in the next breath you show NFS in use?

signed -confused

tracker1 32 minutes ago | parent | prev | next [-]

I accidentally nuked my hosted server's network stack with a config error... my bigger mistake was generating a massive random password for the root account... the remote terminal management console didn't support pasting and the default config only gave you like 30s to login.... not fun at all.

Script all the things. double-check your scripts... always be backing up.

procaryote 2 hours ago | parent | prev | next [-]

This is a useful tip!

but also... who has a dir with 777 permissions? Is that something people do nowadays?

easterncalculus an hour ago | parent | next [-]

My guess would be mounting an NTFS partition - with ntfs-3g it will load everything as 777 just by default, since it can’t translate the permissions.

chasil an hour ago | parent | prev [-]

Well, everybody has 1777 as /tmp (with the sticky bit).

  $ ll -d /tmp
  drwxrwxrwt. 20 root root 4096 Mar  3 12:19 /tmp
  $ mkdir mytmp
  $ chmod 1777 mytmp
  $ ll -d mytmp
  drwxrwxrwt. 1 luser lgroup 0 Mar  3 12:19 mytmp
zahlman 4 days ago | parent | prev | next [-]

I assume using `./*` rather than `.` in the `scp` command would have worked around the issue?

malicka 2 hours ago | parent [-]

Yes, since it would’ve copied the globbed files, rather than the current directory itself.

MomsAVoxell 14 minutes ago | parent | prev | next [-]

Done stupid stuff like this enough times that I just use tar, and also make a sandbox directory to receive it, to double-check whats going to happen, before un—tar’ing it again into the destination intended and/or do a manual move.

Too many burned fingers to not do this little dance almost every other time.

Actually, I lied, I just use rsync like an insane person.

impure an hour ago | parent | prev | next [-]

Ah, file permissions. My old friend. Good thing this happened on a 'local' server and not a remote VPS.

sowbug 2 hours ago | parent | prev | next [-]

Related: In my Bash logout script I have a chmod that fixes authorized_keys. It won't help with scp because that's non-interactive, but it has helped the other 999 times I've forgotten to clean up the mess I made during an ssh session.

TZubiri an hour ago | parent | prev | next [-]

Getting locked out of a server must be a cannonical experienc in the sysadmin journey, like checking the logs to see you are being attacked as soon as your online, or trying to build your own linux from scratch without bloat.

crest 2 hours ago | parent | prev | next [-]

It's nice to see people sharing their mistakes too.

roelschroeven 3 hours ago | parent | prev | next [-]

tl;dr: I you scp -r to your homedir, expect scp to copy not just files and directories but their permissions as well (which I think isn't all that surprising).

ranger_danger 2 hours ago | parent [-]

It's not supposed to do that unless it's newly creating the destination, or you supplied the -p flag to preserve permissions... that's what the entire issue is about; it's a bug that was fixed in 10.3.

Calzifer an hour ago | parent [-]

I wouldn't even expect it on newly created stuff without the -p flag. Normal cp doesn't do it.

binaryturtle 3 hours ago | parent | prev [-]

When I load the site in my (slightly older) Firefox I just get some random junk and gibberish (markov chain generated nonsense?)

<bleep> that nonsense!

theblazehen an hour ago | parent [-]

I suspect you're hitting the page where they're running https://iocaine.madhouse-project.org/

Perhaps you got bot flagged or something