Запуск демона ssh в другом пространстве имен для подключенных клиентов.

La solución de ilkkachu es ingeniosa, usa un solo ejecutable y es probablemente la respuesta correcta. Sin embargo, nunca he podido entender los usos avanzados de awk. Si ilkkachu no hubiera respondido primero, podría haber optado por csplit. csplitdividirá un archivo de texto basado en líneas de contexto(bien, expresiones regulares ). Luego podría tomar esa salida y dividir aún más los archivos con la utilidad splitque ya conoce:

$ csplit --prefix="MySplit." test.csv '/^cust header,/' '{*}'
0
174
134
134

Esos son los recuentos de bytes de cada fragmento (que ignoramos en este caso ). Ahora, itere sobre cada fragmento MySplity divídalo más a su requisito de 20k:

$ for i in MySplit.0*; do
    split --additional-suffix=".$i" -l 20000 "$i"
  done

Por ejemplo, usando -l 2en lugar de 20k, el resultado final dado a su muestra sería (ordenado por extensión):

$ ls -lhXB
total 44K
-rw-r--r-- 1 hunteke hunteke   0 Jun 15 13:31 MySplit.00
-rw-r--r-- 1 hunteke hunteke 174 Jun 15 13:31 MySplit.01
-rw-r--r-- 1 hunteke hunteke  67 Jun 15 13:27 xaa.MySplit.01
-rw-r--r-- 1 hunteke hunteke  81 Jun 15 13:27 xab.MySplit.01
-rw-r--r-- 1 hunteke hunteke  26 Jun 15 13:27 xac.MySplit.01
-rw-r--r-- 1 hunteke hunteke 134 Jun 15 13:31 MySplit.02
-rw-r--r-- 1 hunteke hunteke  67 Jun 15 13:27 xaa.MySplit.02
-rw-r--r-- 1 hunteke hunteke  67 Jun 15 13:27 xab.MySplit.02
-rw-r--r-- 1 hunteke hunteke 134 Jun 15 13:31 MySplit.03
-rw-r--r-- 1 hunteke hunteke  67 Jun 15 13:27 xaa.MySplit.03
-rw-r--r-- 1 hunteke hunteke  67 Jun 15 13:27 xab.MySplit.03
-rw-r--r-- 2 hunteke hunteke 442 Jun 15 13:06 test.csv
1
28.06.2019, 17:25
1 ответ

А, я нашел решение:netnsхранит свои известные пространства имен в /var/run/netns/; это не что иное, как файлы пространств имен(man namespaces/proc/<PID>/ns/.

Итак, мы можем добавить туда пространство имен init, хотя обычно оно отсутствует:

ln -s /proc/1/ns/net /var/run/netns/init

Затем мы можем заставить клиентов открывать оболочку в этом пространстве имен при подключении с возможностьюsshd:

-o ForceCommand='sudo ip netns exec init sudo /bin/bash --login'

Таким образом, демон по-прежнему работает в указанном пространстве имен, отличном от -init, но клиенты подключаются и сразу же входят в сетевое пространство имен init (PID 1 ).


Н.Б. Мы также можем сохранить подключающегося пользователя вместо перехода к root (! )и используйте getent passwdдля получения их обычной оболочки для входа в систему:

# instead of sudo /bin/bash
# *important*: we give ForceCommand='' in *single* quotes
#     so `whomai` et al. are not evaluated until the ForceCommand is invoked.
sudo --user="$(whoami)" "$(getent passwd "$(whoami)" | cut -d: -f7)"

и сохраните любую команду, предоставленную клиентом (ssh user@host cmd), вытащив ее из $SSH_ORIGINAL_COMMANDв начале команды.

1
27.01.2020, 23:41

Теги

Похожие вопросы