You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@jclouds.apache.org by Nipun Udara <y....@gmail.com> on 2014/06/21 16:55:52 UTC

Adding new ssh public key to user

Hi all

I need to add a new ssh public key for a existing user in a ec2 instance. I
would be grateful if somebody can clarify how to do this with jclouds

regards
Nipun Udara

Re: Adding new ssh public key to user

Posted by Ignasi Barrera <na...@apache.org>.
Jclouds will try to connect to the node via SSH to install the public key.

That error appears because jclouds does not know the credentials to use
(has the node been created with jclouds?).

You will have to pass a RunScriptOptions object as a third parameter to the
"runScript" method, with the "overrideLogin*" options set. Those options
should tell jclouds how to login to the node with the existing user to
install the new key.
El 23/06/2014 06:02, "Nipun Udara" <y....@gmail.com> escribió:

> hi lgnasi Barrera,
>
> when i run
>
> computeService.runScriptOnNode("node-id",
>    new AuthorizeRSAPublicKeys(ImmutableSet.of("the public key")));
>
> it gives error as "no credentials found for node"
>
> hi Andrew philips
>
> actually what i need is,  i got a ec2 instance that already have a ssh
> keypair associated with it, but i dont get the private key  so that i need
> to create a new key fair and add it to the instance
>
> regards
> Nipun
>
>
>
> On Mon, Jun 23, 2014 at 3:05 AM, Ignasi Barrera <na...@apache.org> wrote:
>
>> Ni Nipun,
>>
>> If I am not wrong, in AWS an instance can only be associated to one
>> key pair, so I'd assume you're just trying to add a key to an existing
>> user's "authorized_keys" file. You can do that by using the
>> AuthorizeRSAPublicKeys statement [1]. You can do something like:
>>
>> // Add the public key to the default user of the instance
>> computeService.runScriptOnNode("node-id",
>>    new AuthorizeRSAPublicKeys(ImmutableSet.of("the public key")));
>>
>> // Add the public key to a specific ssh config directory
>> computeService.runScriptOnNode("node-id",
>>    new AuthorizeRSAPublicKeys("/home/foo/.ssh", ImmutableSet.of("the
>> public key")));
>>
>>
>> HTH!
>>
>> I.
>>
>> [1]
>> https://github.com/jclouds/jclouds/blob/master/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/statements/ssh/AuthorizeRSAPublicKeys.java
>>
>> On 22 June 2014 21:09, Andrew Phillips <an...@apache.org> wrote:
>> > Hi Nipun
>> >
>> >
>> >> I need to add a new ssh public key for a existing user in a ec2
>> instance.
>> >> I
>> >> would be grateful if somebody can clarify how to do this with jclouds
>> >
>> >
>> > Just to clarify: do you mean creating a new AWS EC2 key pair? Or do you
>> mean
>> > changing the private key for an OS user on a running instance of an EC2
>> AMI?
>> >
>> > Regards
>> >
>> > ap
>>
>
>
>
> --
> Nipun Udara
>
> *Undergraduate*
> *Department of Computer Science & Engineering*
> *University of Moratuwa*
> *Sri Lanka*
>
>

Re: Adding new ssh public key to user

Posted by Nipun Udara <y....@gmail.com>.
hi lgnasi Barrera,

when i run

computeService.runScriptOnNode("node-id",
   new AuthorizeRSAPublicKeys(ImmutableSet.of("the public key")));

it gives error as "no credentials found for node"

hi Andrew philips

actually what i need is,  i got a ec2 instance that already have a ssh
keypair associated with it, but i dont get the private key  so that i need
to create a new key fair and add it to the instance

regards
Nipun



On Mon, Jun 23, 2014 at 3:05 AM, Ignasi Barrera <na...@apache.org> wrote:

> Ni Nipun,
>
> If I am not wrong, in AWS an instance can only be associated to one
> key pair, so I'd assume you're just trying to add a key to an existing
> user's "authorized_keys" file. You can do that by using the
> AuthorizeRSAPublicKeys statement [1]. You can do something like:
>
> // Add the public key to the default user of the instance
> computeService.runScriptOnNode("node-id",
>    new AuthorizeRSAPublicKeys(ImmutableSet.of("the public key")));
>
> // Add the public key to a specific ssh config directory
> computeService.runScriptOnNode("node-id",
>    new AuthorizeRSAPublicKeys("/home/foo/.ssh", ImmutableSet.of("the
> public key")));
>
>
> HTH!
>
> I.
>
> [1]
> https://github.com/jclouds/jclouds/blob/master/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/statements/ssh/AuthorizeRSAPublicKeys.java
>
> On 22 June 2014 21:09, Andrew Phillips <an...@apache.org> wrote:
> > Hi Nipun
> >
> >
> >> I need to add a new ssh public key for a existing user in a ec2
> instance.
> >> I
> >> would be grateful if somebody can clarify how to do this with jclouds
> >
> >
> > Just to clarify: do you mean creating a new AWS EC2 key pair? Or do you
> mean
> > changing the private key for an OS user on a running instance of an EC2
> AMI?
> >
> > Regards
> >
> > ap
>



-- 
Nipun Udara

*Undergraduate*
*Department of Computer Science & Engineering*
*University of Moratuwa*
*Sri Lanka*

Re: Adding new ssh public key to user

Posted by Ignasi Barrera <na...@apache.org>.
Ni Nipun,

If I am not wrong, in AWS an instance can only be associated to one
key pair, so I'd assume you're just trying to add a key to an existing
user's "authorized_keys" file. You can do that by using the
AuthorizeRSAPublicKeys statement [1]. You can do something like:

// Add the public key to the default user of the instance
computeService.runScriptOnNode("node-id",
   new AuthorizeRSAPublicKeys(ImmutableSet.of("the public key")));

// Add the public key to a specific ssh config directory
computeService.runScriptOnNode("node-id",
   new AuthorizeRSAPublicKeys("/home/foo/.ssh", ImmutableSet.of("the
public key")));


HTH!

I.

[1] https://github.com/jclouds/jclouds/blob/master/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/statements/ssh/AuthorizeRSAPublicKeys.java

On 22 June 2014 21:09, Andrew Phillips <an...@apache.org> wrote:
> Hi Nipun
>
>
>> I need to add a new ssh public key for a existing user in a ec2 instance.
>> I
>> would be grateful if somebody can clarify how to do this with jclouds
>
>
> Just to clarify: do you mean creating a new AWS EC2 key pair? Or do you mean
> changing the private key for an OS user on a running instance of an EC2 AMI?
>
> Regards
>
> ap

Re: Adding new ssh public key to user

Posted by Andrew Phillips <an...@apache.org>.
Hi Nipun

> I need to add a new ssh public key for a existing user in a ec2 instance. I
> would be grateful if somebody can clarify how to do this with jclouds

Just to clarify: do you mean creating a new AWS EC2 key pair? Or do  
you mean changing the private key for an OS user on a running instance  
of an EC2 AMI?

Regards

ap