简体   繁体   中英

Passwordless ssh using key authentication in rackspace cloud fails: asks for password

I am trying passwordless ssh connection using public and private key mechanism to a cloudserver(running redhat) in rackspace.

My commands are(in the server):

  1. adduser -g root
  2. mkdir /home//.ssh
  3. copy my public key to /home//.ssh/authorized_keys
  4. chmod 700 /home//.ssh
  5. chmod 600 /home//.ssh/authorized_keys

In the config file of server in the rackspace cloud:

  1. RSAAuthentication yes
  2. PubkeyAuthentication yes
  3. #AuthorizedKeysFile .ssh/authorized_keys

When I try to do "ssh -i my_priv_key @server_ip", it fails and asks me for the password of @server_ip.

When I added the following line to sshd_config on my server, it says Permission denied (publickey,gssapi-keyex,gssapi-with-mic).

Match User PasswordAuthentication no

I have been trying for the last couple of hours but am not able to figure it out. So any idea how to solve this problem.

This doesn't answer your question completely, but I'd like to show you another way to put your SSH keys on your servers, in automation using the Rackspace API. If, for instance, you're using pyrax :

import pyrax
import os

pyrax.set_setting("identity_type", "rackspace")
pyrax.set_setting("username", USER_NAME) # User name
pyrax.set_setting("api_key", API_KEY) # Located in the control panel in settings

# Could also use a credential file
# pyrax.set_credential_file(os.path.expanduser("~/.rackspace_cloud_credentials"))

# Put your SSH key on the Rackspace cloud
pubkey = open("my_priv_key").read()
cs.keypairs.create("testkey", pubkey)

# For demo purposes, grab a sample image, server type (flavor in OpenStack parlance)
flavor_512 = [flavor for flavor in cs.flavors.list() if flavor.ram == 512][0]
ubu_image = [img for img in cs.images.list() if "Ubuntu 12.04" in img.name][0]

# Now we can create the server and assign an ssh key
server = cs.servers.create("ubbie", ubu_image.id, flavor_512.id,
        key_name="testkey")

Your API Key is located in Settings and Contacts within the Cloud Control panel, underneath the security question:

API密钥

Once the server is built, you should be able to grab the ip address

server = cs.servers.get(server.id)
ip = server.accessIPv4

Then simply ssh as root using the key you specified.

ssh -i my_priv_key root@<ip>

If Python isn't your preferred language, there are other options. You can also make direct requests/use curl if that's your thing, as this is part of the Rackspace API and OpenStack/nova proper .

Have you checked the permissions & time settings on the server. Also, have u intentionally removed the username from the post.

Try doing ssh with -v option. This will give more output for debugging.

The easiest way I have found to setup SSH keys on a remote server is to use the ssh-copy-id command.

http://linux.die.net/man/1/ssh-copy-id

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM