# Trouble with SSH on EC2 instance using jclouds



## cen1 (Jan 28, 2016)

I am generating FreeBSD 10 EC2 instances (https://aws.amazon.com/marketplace/...roduct_title?ie=UTF8&sr=0-2&qid=1453939360301) using the jclouds java library.

Instance comes with a username ec2-user and a keypair for login which you specify at creation time. You can su to root, passwordless.

To run commands on a newly created instance, jclouds connects to it via ssh, runs a bash script with sudo (to setup some stuff) and after that, whatever commands you specify. Problem: neither bash nor sudo are preinstalled on FreeBSD.

Because of that, I have to pkg install sudo and bash as root first. If I manually connect to the instance (`ssh -i "privatekey.ppk" ec2-user@ip`) after it gets online I can run:

```
su root
pkg install -y sudo
pkg install -y bash
```
But if I try to run the same commands via jclouds ssh, I get "su: sorry" error. If I try to execute a simple command such as `whoami` I get "not found". And if I try with /usr/bin/whoami I also get "not found".

Example output:

```
/usr/bin/whoami: not found
su: Sorry
pkg: Insufficient privileges to install packages
pkg: Insufficient privileges to install packages
```
It seems to me that with jclouds ssh client I get thrown into some very restricted shell. Any ideas what is happening here?


----------



## cen1 (Jan 28, 2016)

With some trial and error I determined that it must be something with the way command file is parsed into a string. If I execute something like `su - root -c "command && command"` it works normally. But if I read the commands one by one from a file it won't execute them. Maybe it's the line breaks or something in that sense messing up the shell.


----------

