logoalt Hacker News

Disable Your SSH access accidentally with scp

46 pointsby zdwlast Saturday at 5:18 AM14 commentsview on HN

Comments

chasiltoday at 6:30 PM

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.

show 1 reply
TZubiritoday at 6:37 PM

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.

procaryotetoday at 5:53 PM

This is a useful tip!

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

show 2 replies
impuretoday at 6:21 PM

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

zahlmanlast Saturday at 6:16 AM

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

show 1 reply
sowbugtoday at 5:35 PM

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.

cresttoday at 5:27 PM

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

roelschroeventoday at 4:49 PM

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).

show 1 reply
binaryturtletoday at 4:19 PM

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!

show 1 reply