Remote editig with vim

11 views
Skip to first unread message

Anders Persson

unread,
Jul 26, 2008, 4:49:32 PM7/26/08
to v...@vim.org

Hi!

I like to editing remotely with vim, I help som friends with a webbpages, but the

Service don’t allow telnet, so I have found that I can write

:e sftp://<username>@server/

But it keep asking för password everyting I do, I have looked for a way to set

The password, I prefer to enter it one every vim session.

Is there a way ?? I have not found any good tutorial.

 

// Anders

 

John Beckett

unread,
Jul 26, 2008, 9:21:25 PM7/26/08
to vim...@googlegroups.com
Anders Persson wrote:
> Service don’t allow telnet, so I have found that I can write
>
> :e sftp://<username>@server/
>
> But it keep asking för password everyting I do, I have looked

Have you tried
:help ftp

and searched for "password"?

John

Ben Schmidt

unread,
Jul 27, 2008, 1:53:39 AM7/27/08
to vim...@googlegroups.com
Anders Persson wrote:
> Hi!
>
> I like to editing remotely with vim, I help som friends with a
> webbpages, but the
>
> Service don’t allow telnet, so I have found that I can write
>
> :e sftp://<username>@server/ <ftp://<username>@server/>

>
> But it keep asking för password everyting I do, I have looked for a way
> to set
>
> The password, I prefer to enter it one every vim session.
>
> Is there a way ?? I have not found any good tutorial.
>
>
>
> // Anders

For sftp, which is ssh, you probably need to use an ssh agent, which
means you need to use public/private key authentication not password
authentication. This isn't all that hard to set up but can seem daunting
at first. Basically you need to add the contents of your machine's
~/.ssh/id_rsa.pub or id_dsa.pub to the remote machine's
~/.ssh/authorized_keys file, then start your xterm or vim or whatever
within ssh-agent, e.g. ssh-agent vim. You may also like to use
ssh-keygen to add a passphrase to your id_[rd]sa file so the private key
can't be used without a passphrase. Or if id_[rd]sa doesn't exist, you
will need to create it with ssh-keygen. It's the ssh man pages that
detail all this (ssh, ssh-keygen, ssh-agent).

Ben.


Oliver Rath

unread,
Jul 27, 2008, 5:18:36 AM7/27/08
to vim...@googlegroups.com
Anders Persson schrieb:

>
> Hi!
>
> I like to editing remotely with vim, I help som friends with a
> webbpages, but the
>
> Service don't allow telnet, so I have found that I can write
>
> :e sftp://<username>@server/ <ftp://%3Cusername%3E@server/>

>
> But it keep asking för password everyting I do, I have looked for a
> way to set
>
> The password, I prefer to enter it one every vim session.
>
> Is there a way ?? I have not found any good tutorial.
>
assuming you have no ssh access (thats the much better way while here
you can use public keys for avoiding passwords) there is a nice way
storing passwords for ftp:

(taken from vl...@yandex.ru, February 1, 2005 15:19 in
http://www.vim.org/tips/tip.php?tip_id=337):

create .netrc under you home directory and put lines in,
one per ftp machine, like this one:

machine yourftp.somewhere.org login yourlogin password "yoursecret"

HTH,

Oliver

rath.vcf

Tony Mechelynck

unread,
Jul 29, 2008, 4:13:29 PM7/29/08
to vim...@googlegroups.com

Yes, and if you want to try anonymous ftp for any machine not listed,
you (Anders) may add at the very bottom of that file a line such as

default anonymous password anders.u...@telia.com

Note also that that .netrc file (which contains passwords) must not be
world-readable, i.e.

chmod 600 .netrc

otherwise (according to its manpage) the FTP client will abort for
security reasons.


Best regards,
Tony.
--
You know you've been spending too much time on the computer when your
friend misdates a check, and you suggest adding a "++" to fix it.

Charles E. Campbell, Jr.

unread,
Jul 30, 2008, 8:34:35 PM7/30/08
to vim...@googlegroups.com
Anders Persson wrote:
>
> Hi!
>
> I like to editing remotely with vim, I help som friends with a
> webbpages, but the
>
> Service don’t allow telnet, so I have found that I can write
>
> :e sftp://<username>@server/ <ftp://%3Cusername%3E@server/>

>
> But it keep asking för password everyting I do, I have looked for a
> way to set
>
> The password, I prefer to enter it one every vim session.
>
> Is there a way ?? I have not found any good tutorial.
>
:help netrw-ssh-hack

Regards,
Chip Campbell

Ben Schmidt

unread,
Jul 30, 2008, 10:09:40 PM7/30/08
to vim...@googlegroups.com

That seems to contain a lot of the right ideas, but has a few problems:

- The roles of server and client have been reversed (!); it is the
client that needs the key generated and the server which must have
login with that key authorised. As such, the scp command is somewhat
awkward in that description, as it requires your client to also be an
ssh server.
- I believe in OpenSSH, the authorisation file is simply
authorized_keys, without the 2; I believe the 2 is used in some
commercial ssh versions. I think these also use a different key format
to OpenSSH, which necessitates key conversion which can be icky and
probably not worth detailing. At any rate, with current OpenSSH, the
only file used/documented is authorized_keys.
- It actually won't work if you don't save the file in ~/.ssh/id_rsa
(or a handful of other places0 because that's where ssh looks for the
key. Saving it elsewhere will result in ssh not finding it, so it's
not just OK to save it there, it's necessary.
- You might actually want a password, and you can use one if you want,
and then use ssh-agent so you only need to enter it once per session
(or per a certain time limit you can set when you start the agent).
- So...the correct procedure is something more like this...

1. Generate a public/private key pair on your local computer:
ssh-keygen -t rsa
Save the file in ~/.ssh/id_rsa as prompted.
2. You can protect your private key with a passphrase if you
want to, but it isn't necessary (just hit <CR> twice when
asked for a passphrase if you don't want one). If you do use
a passphrase, you will also need to use ssh-agent so you only
have to type it once per session. If you do not use a
passphrase, simply logging in on your local computer
computer or getting access to the key file in any way will be
enough to get access to any ssh servers which have that key
authorized for login.
3. This creates two files:
~/.ssh/id_rsa
~/.ssh/id_rsa.pub
4. Log into the remote ssh server (with ssh) and do the
following:
cd
mkdir -p .ssh
chmod 0700 .ssh
5. On your local machine, execute the following command (one
line) to authorize your key for login on the remote ssh
server:
ssh {serverhostname} cat '>>' '~/.ssh/authorized_keys'
< ~/.ssh/id_rsa.pub
6. Test it out. If you didn't use a passphrase, just do
ssh {serverhostname}
and you should be logged in without needing to type anything.
If you did use a passphrase, do
ssh-agent $SHELL
ssh-add
ssh {serverhostname}
You will be prompted for your key password when you ssh-add,
but not when you ssh. For use with Vim, you can do ssh-agent
vim and then :!ssh-add from within Vim. Alternatively, you
can start the terminal you run Vim in with ssh-agent (e.g.
ssh-agent xterm &), and ssh-add whenever you feel like it.

Ben.


Reply all
Reply to author
Forward
0 new messages