Using SFTP to set up SSH key login

2

1

Actually... a server that does not have an SSH shell?

When you login, many hosts say:

Shell access is not enabled on your account!
If you need shell access please contact support.

But they support SFTP and id_rsa login for SFTP.

Is it possible to use the SFTP on the command line to transfer my public key for login?

William Entriken

Posted 2016-12-13T16:38:27.917

Reputation: 2 014

This message suggests that public-key is actually in place but the shell in /etc/passwd if set to some jail-shell instead of bash or whatever interactive shell. – tonioc – 2016-12-14T12:30:42.747

Answers

2

It depends on the configuration, but generally, you should be able to replicate what ssh-copy-id does in sftp batch file:

!cat ~/.ssh/id_rsa.pub > /tmp/authorized_keys # prepare filename with keys
mkdir .ssh
put /tmp/authorized_keys .ssh/
!rm /tmp/authorized_keys # cleanup

but this has its limitations:

  • If there is already some key in authorized_keys, it will get overwritten (you can download the existing file locally and append locally
  • If the directory already exists, it might fail
  • It takes only id_rsa (as a proof of concept). Adding other keys is quite straightforward

Storing the above file in copy-id.sftp and running sftp -b copy-id.sftp your_host should do the job.

Jakuje

Posted 2016-12-13T16:38:27.917

Reputation: 7 981