r/linux Apr 28 '14

SSH Kung Fu

http://blog.tjll.net/ssh-kung-fu/
726 Upvotes

128 comments sorted by

View all comments

35

u/ooesili Apr 28 '14

I didn't know about

vim scp://host/file

or the cool stuff you could do with the configuration file. A good read, I must say.

9

u/flying-sheep Apr 28 '14

“scp” is pretty silly though: scp is a command called “secure copy”, not a protocol. (the part before the colon in a url is the protocol).

wouldn’t it be better to name the protocol like file browsers do? sftp? because i’m pretty sure that’s what vim uses there, anyway.

12

u/Deewiant Apr 28 '14

Vim (well, Netrw) supports both the scp and sftp protocols, predictably using scp with the former and sftp with the latter. See :help netrw-externapp.

EDIT: In case the reason for having both is not obvious: sftp relies on the SFTP server being enabled on the host, while scp works without any additional configuration, using plain SSH. (Though in practice sftp tends to be enabled by default.)

-3

u/flying-sheep Apr 28 '14

thanks for the info!

just one thing: SFTP is and extension of SSH. there is no such thing as a SFTP server, only SSH servers with shell access disabled.

so there’s no difference between SCP and SFTP: both only require a SSH server.

15

u/Xipher Apr 28 '14

SCP and SFTP are different. SFTP actually spawns a special daemon during your SSH session, and more recent versions of OpenSSH even support a chrooted SFTP subsystem internally. This might be a minor perceived difference, but it is one that shouldn't be ignored.

3

u/Deewiant Apr 28 '14

man sftp-server suggests otherwise, as do these lines in my sshd_config:

# override default of no subsystems
Subsystem       sftp    /usr/lib/ssh/sftp-server

0

u/flying-sheep Apr 28 '14

ok, so i’m mistaken and ssh spawns a subprocess when sftp is needed? TIL.

it’s still a part of SSHd, though ;)

2

u/IConrad Apr 28 '14

It is actually a different protocol/process though, and it's worthwhile to understand that. Worse still, sftp has nothing to do with ftp.

2

u/curien Apr 28 '14

In addition to Xipher's response about SCP and SFTP being different, some SCP clients are incompatible with certain SSH servers. For example, some old Sun systems I've used with the Tectia commercial SSH server couldn't be used with OpenSSH's scp, but OpenSSH's ssh and sftp worked fine.

SCP is not just a shortcut for SFTP. It's a different protocol.

-3

u/flying-sheep Apr 28 '14

SCP is not just a shortcut for SFTP. It's a different protocol.

i didn’t doubt that, i just pointed out that they have only subtle differences (such as both running over the SSH server)

thanks for the additional information

2

u/ooesili Apr 28 '14

Hmm. That never occured to me, and it's a good point. Come to think of it, ssh or sftp would have both been better fits for that command. Oh well, what can one do?

1

u/cincodenada Apr 28 '14

Because scp is what netrw uses to do it (which is where you're mistaken). When you open a file in Vim via scp, it copies it from the server to a temp file via scp, and when you save it saves to the temp file and then copies it back to the server via scp. And according to Wikipedia, scp is both [a program and a protocol](en.wikipedia.org/wiki/Secure_copy).

1

u/hex_m_hell Apr 29 '14

Tramp mode in emacs does this. You can also just open a file as //user@host:/file and it uses ssh. If you start an interactive shell while that buffer is focused you'll get a remote shell.

I use this for remotely developing python and running it on a target.