# Copy public key to FreeBSD error



## eiger3970 (Feb 25, 2020)

Hello, I'm trying to copy a public key to FreeBSB and I always use the same command, however FreeBSD syntax is a little different to what I'm used to.
My command is:

```
linuxmint@linuxmint:~$ cat ~/.ssh/id_rsa.pub | ssh admin@192.168.1.170 "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"
Password for admin@pfSense.localdomain:
```

However I receive the error:

```
usage: mkdir [-pv] [-m mode] directory_name ...
```


----------



## sko (Feb 26, 2020)

why don't you just use "ssh-copy-id"? It does exactly what you are trying to do and works over several platforms (I'm using it e.g. between FreeBSD, OpenBSD and smartos/illumos hosts)

As for your command, I suspect you are feeding the output of 'cat' to 'mkdir' which will not work. Maybe bash is doing something different here and ignores stdin for mkdir. Never use bashisms if you intend do be compatible - bash is almost never a standard shell except in the linux ecosystem!


----------



## eiger3970 (Feb 26, 2020)

Thank you for the informative reply.
I've used that command before ssh-copy-id was created.  Always worked for me up until today.
I'll try ssh-copy-id.
May I ask what language to use, as I appreciate your bashism comment?


----------



## eiger3970 (Feb 26, 2020)

Sweet!  That worked.  I had to name my key as per the previously generated key id_rsa.pub.  Didn't feel like changing my public key and copying to all the clients.


eiger3970 said:


> Thank you for the informative reply.
> I've used that command before ssh-copy-id was created.  Always worked for me up until today.
> I'll try ssh-copy-id.
> May I ask what language to use, as I appreciate your bashism comment?


----------



## eiger3970 (Feb 26, 2020)

Hmm, rebooted FreeBSD OS and id_rsa.pub key is no longer in /root/.ssh?


----------



## SirDice (Feb 26, 2020)

Because you're not on FreeBSD, you're using pfSense. pfSense is a highly modified FreeBSD _derivative_. 

PC-BSD, FreeNAS, XigmaNAS, and all other FreeBSD Derivatives


----------



## eiger3970 (Feb 27, 2020)

Thanks, will ask on pfSense forum.


----------

