I ended up testing SSH configuration separately from the command line to get this part. I think there was a problem with SSH keys as I used PuTTY to create them, and this format may not have been compatible with OpenSSH, which Linux uses.
So, first I created new SSH keys on my Linux machine without a password for the private key, which made two files id_rsa and id_rsa.pub for me. Then I copied the public key string from id_rsa.pub to the authorized_keys file on the production server. Then I checked from the command line. Once this works, I tested Fabric.
So, the configuration has changed like this:
from fabric.api import * env.use_ssh_config = True env.hosts = ["myserver"] env.user = "root" env.key_filename = "/home/myusername/.ssh/id_rsa" env.password = "" env.port = 22 def testlive(): run("ls")
Here is my SSH configuration in /home/myusername/.ssh/config:
Host myserver hostname myserver.net port 22 IdentityFile ~/.ssh/id_rsa
Now it works fine when I run fab testlive from the command line.
source share