Skip to content

Commit

Permalink
Easiest SSH hosting for file sharing
Browse files Browse the repository at this point in the history
  • Loading branch information
QuAzI committed Apr 6, 2024
1 parent 8cfb886 commit 366c4d9
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 13 deletions.
3 changes: 0 additions & 3 deletions content/posts/2023-08-24-obsidian-to-hugo/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,7 @@ tags: []
Теперь можно писать статьи. Я придерживаюсь следующей структуры: создаётся директория `content/posts/YYYY-MM-DD-some-title` , в ней создаётся `index.md` , вставляется шаблон страницы, добавляется содержимое статьи и туда же складываются все картинки и прочие файлы к статье. В таком виде всё отлично видно в любом ПО работающим с Markdown, включая VS Code и всякие WebIDE на GitHub/GitLab. Структура практически совпадает со статичным сайтом который сгенерируется и для этой статьи выглядит следующим образом
```
└── content
    ├── _index.md
    ├── about.md
   └── posts
   ├── _index.md   
   └── 2023-08-24-obsidian-to-hugo
      ├── Obsidian_20230824_165731_siGv.png
      ├── Obsidian_20230824_165922_wxWu.png
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
72 changes: 72 additions & 0 deletions content/posts/2024-04-06-ssh-server-for-sharex/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
---
title: SSH сервер для загрузки файлов на хостинг
description: Простой, но безопасный хостинг для скринов/копипаст/файлов
date: 2024-04-06 14:29:48 +03:00
categories: blog
layout: post
tags:
- ssh
- ShareX
- Hosting
- Docker
---
Простейший собственный хостинг для загрузки из [ShareX](../2022-10-29-sharex/index.md) можно поднять в Docker.
Для примера у меня запущен стандартный nginx в режиме простого файл-сервера, настроен раздавать статичный контент из директории ./html/ . Трафик на него по заданному HOSTNAME раскидывает балансировщик [nginx-proxy](https://hub.docker.com/r/nginxproxy/nginx-proxy) . Я решил что буду заливать файлы из ShareX в поддиректорию ./html/files/ которая будет доступна из Инета как HOSTNAME/files/ .
В качестве SFTP-сервера будет выступать образ [linuxserver/docker-openssh-server](https://github.com/linuxserver/docker-openssh-server)
Можно было бы авторизоваться автоматом по ключам пользователя, например указав в PUBLIC_KEY_URL ключ пользователя на гитхабе, но ShareX на данный момент ещё не умеет загружать ключи из SSH-агента, поэтому приходится включить PASSWORD_ACCESS и задать уникальный USER_PASSWORD для загрузки файлов.
```yaml
services:
site:
image: nginx:latest
volumes:
- ./html:/usr/share/nginx/html
environment:
- VIRTUAL_HOST=HOSTNAME
- LETSENCRYPT_HOST=HOSTNAME
- LETSENCRYPT_EMAIL=admin@HOSTNAME
restart: always

ssh-server:
image: lscr.io/linuxserver/openssh-server:latest
container_name: openssh-server
hostname: openssh-server #optional
environment:
#- PUID=1000
#- PGID=1000
#- TZ=Etc/UTC
#- PUBLIC_KEY=yourpublickey #optional
#- PUBLIC_KEY_FILE=/path/to/file #optional
#- PUBLIC_KEY_DIR=/path/to/directory/containing/_only_/pubkeys #optional
- PUBLIC_KEY_URL=https://github.com/USERNAME.keys #optional
- SUDO_ACCESS=false #optional
- PASSWORD_ACCESS=true #optional
- USER_PASSWORD=pass #optional
#- USER_PASSWORD_FILE=/path/to/file #optional
- USER_NAME=user #optional
- LOG_STDOUT= #optional
volumes:
- ./cont-init.d/:/custom-cont-init.d:ro
- ./html/files:/files
ports:
- 2222:2222
restart: unless-stopped
```
Так же во избежание казусов создаём файл `cont-init.d/nologin`
в котором отключаем возможность логина в консоль, нас интересует только SFTP-сервер.
```shell
#!/usr/bin/with-contenv bash
echo Disable shell
chsh -s /sbin/nologin user
```
Остальные опции по умолчанию выключены в `/etc/ssh/sshd_config`
```
AllowTcpForwarding no
GatewayPorts no
X11Forwarding no
```
Не хватает только CREATE ONLY прав, так как обновление/удаление/листинг/выполнение нам из ShareX не нужны.
Настраиваем ShareX, радуемся
![](image-20240406145325.png)
15 changes: 5 additions & 10 deletions themes/m10c/assets/css/_extra.scss
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ pre {
list-style: none;
margin: 0;
padding: 0;
//font-size: 0.6em;

li:not(:last-child)::after {
display: inline-block;
Expand All @@ -68,6 +67,11 @@ pre {
}
}

// pc, tablet or phone with good display
// @media screen and (color) and (not (any-pointer: none)) {
// .pc { display: inline; }
// }

@media (max-width: 1680px) {
.app-container {
margin-right: 22rem;
Expand Down Expand Up @@ -112,10 +116,6 @@ pre {
max-width: 100%;
margin: 0 0;
padding: 0.7rem 1.5rem;

// .breadcrumb {
// display: none;
// }
}

.post-header {
Expand Down Expand Up @@ -144,7 +144,6 @@ pre {
}
}

// styles for Print and e-books (include 4096 colors)
@media print, monochrome, amzn-mobi, amzn-kf8, (hover: none) and (any-pointer: none) {
body {
color: #000000;
Expand Down Expand Up @@ -177,10 +176,6 @@ pre {
.app-container {
padding: 0 1.5rem;

// .breadcrumb {
// display: none;
// }

.post,
.posts-list-item {
font-size: 1.2em;
Expand Down

0 comments on commit 366c4d9

Please sign in to comment.