Компактный способ иметь один и тот же открытый ключ для многих идентификаторов серверов на известных _хостах ssh

Я создал следующий скрипт Python, который делает следующее:

  1. Переключение устройства по умолчанию на следующее устройство в списке (с переходом )независимо от идентификатора
  2. Перемещает все запущенные приложения на это устройство.
  3. Отправляет уведомления в графический интерфейс с именем устройства.
#!/usr/bin/env python3
import subprocess
# Toggle default device to the next device (wrap around the list)
cards_info = subprocess.run(['pacmd','list-sinks'], stdout=subprocess.PIPE)
card_indexes = subprocess.run(['grep', 'index'], stdout=subprocess.PIPE, input=cards_info.stdout)
indexes_list = card_indexes.stdout.decode().splitlines()
card_descriptions = subprocess.run(['grep', 'device.description'], stdout=subprocess.PIPE, input=cards_info.stdout)
indices = [i for i, s in enumerate(indexes_list) if '*' in s]
if (len(indices) != 1):
    print("Error finding default device")
    exit(1)
default_index = indices[0]
next_default = 0
if (default_index != (len(indexes_list) - 1)):
    next_default = default_index + 1
next_default_index =  (indexes_list[next_default].split("index: ",1)[1])
subprocess.run(['pacmd','set-default-sink %s' %(next_default_index)], stdout=subprocess.PIPE)

# Move all existing applications to the new default device
inputs_info = subprocess.run(['pacmd','list-sink-inputs'], stdout=subprocess.PIPE)
inputs_indexes = subprocess.run(['grep', 'index'], stdout=subprocess.PIPE, input=inputs_info.stdout)
inputs_indexes_list = inputs_indexes.stdout.decode().splitlines()
for line in inputs_indexes_list:
    input_index =  (line.split("index: ",1)[1])
    subprocess.run(['pacmd','move-sink-input %s %s' %(input_index, next_default_index)], stdout=subprocess.PIPE)

# Send notification to the GUI
descriptions_list = card_descriptions.stdout.decode().splitlines()
if (len(descriptions_list) == len(indexes_list)):
    description =  (descriptions_list[next_default].split("= ",1)[1])[1:-1]
    args = ["notify-send", "Default audio card changed", 'Default audio card was set to %s' %(description)]
    subprocess.run(args, stdout=subprocess.PIPE)

Назначил скрипту сочетание клавиш, и теперь моя жизнь счастлива

1
04.12.2019, 13:35
1 ответ

Как только я отправил вопрос,Я заметил, что в руководстве по sshd есть запись о похожем файле (ssh _known _hosts ).

man sshd

В руководстве указано:

Hostnames is a comma-separated list of patterns (‘*’ and ‘?’ act as wildcards); each pattern in turn is matched against the canonical host name (when authenticating a client) or against the user-supplied name (when authenticating a server). A pattern may also be preceded by ‘!’ to indicate negation: if the host name matches a negated pattern, it is not accepted (by that line) even if it matched another pattern on the line. A hostname or address may optionally be enclosed within ‘[’ and ‘]’ brackets then followed by ‘:’ and a non-standard port number.

Поскольку формат файла ssh _известных _хостов совпадает с известными _хостами, ответ на мой вопрос заключается в использовании подстановочных знаков:

a0?b??c0?d??,192.168.*.* {signature-algorithm} {public-key-string} {comment}

Тем не менее, это по-прежнему не ограничивает только те значения, которые я хотел иметь, поэтому, если кто-то знает, как еще ограничить это, сообщите мне об этом.

a0?b??c0?d?? также может быть a0ibx3c0wdxy

1
27.01.2020, 23:40

Теги

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