Can't connect to a remote server with Nautilus and a private key
Solution 1
I don't see why key selection dialogue should appear at all. It's up to the server to offer authentication methods it's willing to accept and up to the client to provide the credentials.
One of the most common methods for providing those details is using the ssh-agent which you don't appear to be running. This is a little snippet I've put in my ~/.profile
to make sure my ssh-agent is always running:
run_ssh_agent() {
ssh-agent | grep -vi 'agent pid' > ~/.ssh-agent
. ~/.ssh-agent
}
if [[ -f ~/.ssh-agent ]]; then
. ~/.ssh-agent
if [[ -n ${SSH_AGENT_PID} ]]; then
if ! ps -p ${SSH_AGENT_PID} | grep 'ssh-agent' &>/dev/null; then
run_ssh_agent
fi
fi
else
run_ssh_agent
fi
Put the code there, log out of your X session, log back in, open a terminal and add your key to your agent:
ssh-add /path/to/your/private_key
Verify that it's added by running ssh-add -l
and connect to the server using Nautilus without providing the password.
Solution 2
The short version (skip the script) of Marcin Kaminski's solution is
ssh-agent
ssh-add /path/to/your/private_key
nautilus sftp://user@server
. I think it's easier to start with, to test if the solution works. I had the same problem after setting PasswordAuthentication no
in /etc/ssh/sshd_config
and these three commands solved my problem.
Solution 3
I could connect to my server in Nautilus (Ubuntu 12.04) using a private key by doing the following:
- In Nautilus, select menu: "File" -> "Connect to Server..."
- Change "Type:" to "SSH"
- Enter the address of the server in the "Server:" field (omitting username@)
- Enter your user name after "User name:" but leave the password field empty.
When you hit "Connect" a dialog should appear telling you a password is needed to unlock the key. In my case the key was not the default "~/.ssh/id_rsa", so communication between the SSH client and server must have revealed to Nautilus what key should be used.
After entering the password, a new Nautilus window opened where I chould browse the files on my server. In the left pane I now have a shortcut "SFTP for user on server" which I can also use to u(n)mount the server file system.
Related videos on Youtube
Desmond Hume
Updated on September 18, 2022Comments
-
Desmond Hume over 1 year
The remote server requires a private key and passphrase for authentication. I'm trying to connect to the server as
root
(on that server) from Nautilus running on behalf of my non-root account on my local Ubuntu desktop. The private key that is needed for authentication is not located in~/.ssh
(I've already got other keys there) but I have it in another directory.In addition to the obvious approach, I tried putting
root@server
in the "Server" field and leaving "User name" and "Password" fields blank, putting the passphrase in the "Password" field, but it still says "Permission denied" and it doesn't ask for the private key at any point.I also tried
ssh-add path/to/privatekey
, but it says "Could not open a connection to your authentication agent.", however I'm not sure ifssh-add
is even relevant here.I can ssh into the server from the terminal just fine with
ssh -i <...>/id_rsa root@server
and answering the passphrase question that follows.
-
Desmond Hume over 11 yearsThanks but I'd rather expect a key location dialog, which never appears. Please see the edits I made to provide more details (one is that I'm trying connect as
root
). -
Desmond Hume over 11 yearsWhere did you put that key instead? I put my key file into
~
and even changed its permissions to777
but Nautilus still doesn't seem to be able to locate it. -
jmidgren over 11 yearsIt's stored in my ssh folder but with another file name: ~/.ssh/id_rsa_example.
-
jmidgren over 11 yearsChanging the permissions will probably only make things worse. Your private key must only be available to you and should thus have 600 permissions. Also check out the permissions of your ~/.ssh folder and your home folder. Depending on if you are the only member of the group that owns those folders or not, you may have to restrict access to group members as well (e.g. 700 on ~/ and ~/.ssh).
-
gannex over 7 yearsthanks for simplifying that answer for me. This works perfectly :-)