Если вам нужно сделать это в скрипте или поддерживать каталоги с недоказуемыми именами:
cd $(python -c $'import os\nfor entry in os.listdir(b"."):\n if os.path.isdir(entry):\n os.write(1, entry);break\nelse: os.write(1, b".")')
Он работает, если в каталоге есть файлы, независимо от порядка их сортировки относительно каталогов. Он работает для скрытых каталогов, когда cd */ терпит неудачу. Он работает, если имя не отображается в текущей локали, когда ls печатает ?? вместо имени.
Вы также можете попробовать использовать опцию ProxyCommand.
Он дает вам возможность управлять командой, используемой для подключения к серверу; звучит неприятно, но я еще не нашел с ним никаких проблем.
Из ProxyCommand docs:
ProxyCommand
Specifies the command to use to connect to the server. The command string extends to the end of the line, and is executed using the user's shell ‘exec’ directive to avoid a
lingering shell process.
In the command string, any occurrence of ‘%h’ will be substituted by the host name to connect, ‘%p’ by the port, and ‘%r’ by the remote user name. The command can be basically
anything, and should read from its standard input and write to its standard output. It should eventually connect an sshd(8) server running on some machine, or execute sshd -i
somewhere. Host key management will be done using the HostName of the host being connected (defaulting to the name typed by the user). Setting the command to “none” disables
this option entirely. Note that CheckHostIP is not available for connects with a proxy command.
This directive is useful in conjunction with nc(1) and its proxy support. For example, the following directive would connect via an HTTP proxy at 192.0.2.0:
ProxyCommand /usr/bin/nc -X connect -x 192.0.2.0:8080 %h %p
Допустим, у вас есть команда или скрипт, который выполняет детонацию в вашей папке: knock.sh <host> <port1 port2 ... portX>
И вы хотите подключиться к некоторому хосту: myhost.net
Вы можете добавить следующее к вашему ~/.ssh/config
Host thehost
HostName myhost.net
ProxyCommand bash -c 'knock.sh %h <port1 port2 ... portX>; nc %h %p'
% h => имя хоста (myhost.net)% p => порт (22) И вы можете подключиться к своему host с: ssh user@thehost
Вы также можете использовать эту опцию непосредственно из командной строки с помощью: ssh -o ProxyCommand="bash -c 'knock.sh %h <port1 port2 ... portX>; nc %h %p'" user@myhost.net
Если программа записывает данные в stdout по умолчанию, он становится скрытым, если вам нужно его увидеть, добавьте -v после ssh.
Также обратите внимание, что ssh должен выполнить детонацию перед выполнением соединения, поэтому общее время, необходимое для завершения соединения, будет больше.
У меня есть текущая конфигурация, работающая с переадресацией портов, и никаких проблем с ней еще нет.