Posted on
Spread the love

The sshfs options that may be important: -o reconnect (says trying to reconnect instead of errors).

If you work a lot with data from the root, you can (need) do an idmap:

-o idmap = user. It works as follows: if we connect as a pupkin @ server user, and locally work as a vasiliy user, then we say “assume that the pupkin files are the vasiliy files”. well, or “root” if we connect as root.

In my case, idmap is not needed because the usernames (local and remote) are the same.

Note, it only works comfortably if we have an ssh-key (see the beginning of the article), if not – password authorization drives out a 2-3 connection.

You can disable it back with the fusermount -u / path command, however, if the connection is stuck (for example, there is no network), then you can / should do it from under the root: sudo umount -f / path.

Remote code execution PuTTY download

ssh can execute a command on a remote server and close the connection immediately. The simplest example is:

ssh user @ server ls / etc /

Print the contents of / etc / to us on the server, and we will have a local command line.

Some applications want to have a controlling terminal. They should be run with the -t option:

ssh user @ server -t remove_command

By the way, we can do something like this:

ssh user @ server cat / some / file | awk ‘{print $ 2}’ | local_app

This brings us to the following feature:

Forward stdin / out

Suppose we want to make a request to the program remotely, and then put its output in a local file

ssh user@8.8.8.8 command> my_file

Suppose we want to put a local output remotely

mycommand | scp – user@8.8.8.8: / path / remote_file

Let’s complicate an example – we can transfer files from the server to the server: Make a chain to put stdin on 10.1.1.2, which is not available to us outside:

mycommand | ssh user@8.8.8.8 “scp – user@10.1.1.2: / path / to / file”

There is such a puzzling method of using pipe (kindly suggested in the comments in LJ):

tar -c * | ssh user @ server “cd && tar -x”

Tar packs files by mask locally, writes them to stdout, from where ssh reads them, transfers to stdin on a remote server, where cd ignores them (does not read stdin), and tar reads and unpacks. So say the scp for the poor.