# Can't connect the custom repository via SSH



## alphachi (Sep 24, 2021)

I want to provide a custom repository via SSH, because this needn't install any package like apache or nginx, even pkg itself.

The server IP is 10.0.0.1/24:

```
root@Server:~ # cat /usr/local/etc/pkg/repos/FreeBSD.conf /usr/local/etc/pkg/repos/Local.conf
FreeBSD: {
  enabled: no
}
Local: {
  url: "file:///var/pkg"
}
root@Server:~ # pkg info
The package management tool is not yet installed on your system.
Do you want to fetch and install it now? [y/N]: y
Bootstrapping pkg from file:///var/pkg, please wait...
[Server] Installing pkg-1.17.2...
[Server] Extracting pkg-1.17.2: 100%
pkg-1.17.2                     Package manager
```

The client IP is 10.0.0.2/24:

```
root@Client:~ # cat /usr/local/etc/pkg/repos/FreeBSD.conf /usr/local/etc/pkg/repos/Local.conf
FreeBSD: {
  enabled: no
}
Local: {
  url: "ssh://10.0.0.1/var/pkg"
}
root@Client:~ # scp 10.0.0.1:/var/pkg/Latest/pkg.txz .
pkg.txz                                                        100% 7472KB  56.2MB/s   00:00
root@Client:~ # pkg info
The package management tool is not yet installed on your system.
Do you want to fetch and install it now? [y/N]: y
Bootstrapping pkg from ssh://10.0.0.1/var/pkg, please wait...
pkg: Error fetching ssh://10.0.0.1/var/pkg/Latest/pkg.txz: Invalid URL scheme
A pre-built version of pkg could not be found for your system.
Consider changing PACKAGESITE or installing it from ports: 'ports-mgmt/pkg'.
```

I think the ssh-repo format is wrong, but I can't find any example for this.


----------



## SirDice (Sep 24, 2021)

pkg(8) uses fetch(3) and that only supports FTP, HTTP(S) and the file scheme. If you want to do this with only the base system tools then ftpd(8) or NFS are an option. But really the simplest solution is to use www/nginx or www/lighttpd, basically any webserver that can serve a directory of files will do.


----------



## ljboiler (Sep 24, 2021)

*ssh* is not a valid scheme for a URL.


----------



## alphachi (Sep 24, 2021)

pkg-ssh(8):

```
...
     pkg ssh provides a minimal package server.  It is most commonly used with
     the SSH transport protocol.

     This command is not meant to be used by the user.  pkg(8) will start the
     server automatically through ssh(1) when the ssh:// scheme is specified
     in the repository configuration.
...
```

pkg.conf(5):

```
...
     For a MIRROR_TYPE of NONE, any of the URL schemes supported by
     libfetch(3) can be used, including: http://, https://, ftp://, or
     file://.  In addition a ssh:// URL scheme is also supported.  Where
     MIRROR_TYPE is SRV, you should use a pkg+http:// or pkg+https:// (etc.)
     URL scheme.  Using an http:// URL implies that the hostname part is a
     simple hostname according to RFC 2616, and is no longer accepted.
...
```

In addtion, some options like PKG_SSH_ARGS and SSH_RESTRICT_DIR exist in pkg.conf(5).
I feel puzzled...


----------



## VladiBG (Sep 24, 2021)

It's not included in pkg-static you need to install pkg first from FreeBSD repo via http(s) `pkg bootstrap`


----------



## SirDice (Sep 24, 2021)

Looks like it's a relatively new addition to pkg(8). But the problem is that pkg(7) doesn't support it. So you'll need to find another way to bootstrap it first.


----------



## alphachi (Sep 26, 2021)

Yes, pkg(7) doesn't support SSH and pkg(8) supports it:

```
root@Server:~ # pkg info
pkg-1.17.2                     Package manager
root@Server:~ # pkg which `man -aw pkg-ssh pkg.conf`
/usr/local/man/man8/pkg-ssh.8.gz was installed by package pkg-1.17.2
/usr/local/man/man5/pkg.conf.5.gz was installed by package pkg-1.17.2
```

But bootstrap is easy:

```
root@Client:~ # scp 10.0.0.1:/var/pkg/Latest/pkg.txz .
pkg.txz                                                        100% 7472KB  55.8MB/s   00:00
root@Client:~ # pkg add pkg.txz && rm pkg.txz
[Client] Installing pkg-1.17.2...
[Client] Extracting pkg-1.17.2: 100%
root@Client:~ # pkg info
pkg-1.17.2                     Package manager
```


----------



## astyle (Jul 10, 2022)

PHEEWW.. in /usr/local/etc/pkg/repos/custom.conf, I needed to adjust the ssh:// URL to ssh://[user@]hostname to avoid having root be the user that SSH picks on the barebones (only to be rejected by server with the package repo!) It's on my own home net anyway.  The SSH URL needs to be in this format: `ssh://user@hostname/path/to/poudriere/repo`, same as where you  find packages after a Poudriere run!


----------

