Calculate file hash on remote server accessed via SFTP [duplicate] - sftp

This question already has an answer here:
How to perform checksums during a SFTP file transfer for data integrity?
(1 answer)
Closed 4 years ago.
I am connecting to a remote host via SFTP to transfer files.
Is it possible to determine the hash of a file on the remote host, without downloading it first? If so how?

As you are using SFTP, then you should also have SSH access to this machine, as SFTP is FTP on top of SSH.
This means that you should be able to execute remote commands on this machine - try some of the approaches mentioned here: How to use SSH to run a shell script on a remote machine?
For example - on macOS, there's a command md5 (md5sum on linux) which will accept a path to a file as an argument, and returns a hash. That should help you get started!

Related

How do I connect to a RDS MySQL instance from RStudio via a bastion host?

I would like to use RStudio for analysis of data on a MySQL instance. This is a AWS RDS MySql instance that is only accessible via a jump box / bastion host. I have the credentials necessary to connect to the jump box, and from the jump box to the RDS instance. What do I need to do be able to query this DB directly from within the RStudio console?
I can connect (using the Terminal tab in RStudio)to the jump box using:
ssh -p 22xx user#ip.add.re.ss
Then I can connect to RDS mysql using:
mysql -u username -p database -h hostname.us-east-1.rds.amazonaws.com
I can connect and do manual mysql commands from within RStudio terminal, but I don't seem to be able to do anything with the DB from the RStudio console.
Sorry for opening a 2yo thread, but for everyone dealing with this issue as I am - I found this thread and it looks like it works (connecting with MySQL via ssh from R Studio).
You should use something which is called port forwarding. Some details
are here
(https://help.ubuntu.com/community/SSH/OpenSSH/PortForwarding) For
example, say you wanted to connect from your laptop to
http://www.ubuntuforums.org using an SSH tunnel. You would use source
port number 8080 (the alternate http port), destination port 80 (the
http port), and destination server www.ubuntuforums.org. :
ssh -L 8080:www.ubuntuforums.org:80 Where should be
replaced by the name of your laptop.
This is done for whole computer so you dont need to do this from r
studio.
Offcourse you need to forward your port to 3036. But you need special
privilige on the server. Because on most hosting you can only connect
from localhost (for example from PHP)
Source: https://www.py4u.net/discuss/881859

Unable to SFTP Bitnami (Wordpress) Google Cloud Instance

I'm trying to SFTP Compute Engine from MAC using Filezilla. I can SSH with port 22 without any problem. But I need R/W/D access to my files and trying SFTP to port 21 and getting the following error,
Command: keyfile "/bitnami-google-api-project-4xxxxxxxxxx.pem"
Command: open "bitnami#104.xxx.xxx.xxx" 21
Error: Connection refused
Error: Could not connect to server
I referred a couple of similar threads here nothing make this work, sofar I did,
Bitnami Key added in Google Compute Engine and both are same Added.
PEM key file (MAC) in FileZilla settings.
I'm using root password with default username
Anything I'm missing from the doc to follow to get access through 21?
SFTP runs over an SSH session, usually on TCP port 22. In the Bitnami Stack SFTP is configured to use port 22. In the link below you will find information about how to upload files using SFTP using Bitnami Cloud Images on Google Cloud:
https://docs.bitnami.com/google/faq/#how-to-upload-files-to-the-server-with-sftp
If you want to use SFTP on any other port, you need to open that port on your server and configure SFTP to use port 21. You can open a port on your server following the steps described in the guide below:
https://docs.bitnami.com/google/faq/#how-to-open-the-server-ports-for-remote-access

How do I access remote files using emacs running locally?

Normally, to edit my files, I need to ssh into host sunfire and on that host, I need to ssh into another host xcnc1. My files are on xcnc1 which I can only access through sunfire.
My question is how can I access that xcnc1 files from my local machine?
Use Tramp with ad-hoc proxies. Something like C-x C-f /ssh:user1#sunfire|ssh:user2#xnc1:/path/to/file. If user1 or user2 are the same user as your local one, you could omit them.

Implementing simple software updater using rsync

I'm trying to find a way to update client software while reducing traffic and update server load.
Case:
Server is just http server that has latest non compressed/packed version of software.
Client uses rsync to download changes
Does server have to run rsync instance/host/service (idk how to call it) in order to produce delta files?
Seen some forum question about downloading files with rsync. It seemed like server didn't need rsync instance. If server isn't running rsync instance is that download gonna be done without delta files?
Do you know other solutions which can reduce network and server load?
The server doesn't need any special software other than a ssh server.
I was incorrect about this for your use case. I believe what you are looking for is daemon mode rsync for the server. This has rsync listen on a port to serve requests.
I misunderstood what you were trying to do at first. However in theory it might still be able to be done with only ssh or telnet, I think the daemon mode is a better solution.
See: SSH vs Rsync Daemon

How do I refer to my local computer for scp'ing when logged into remote?

This must be a really simple question, but I am trying to move a file from a remote server to my local computer, while logged into the remote (via ssh).
All of the guides say to just use
scp name#remote:/path/to/file local/path/to/file
But as far as I can understand, that would be what I would use from my local machine. From the remote machine, I assume that I want to use something like
scp /path/to/file my_local_computer:/local/path/to/file
but (if that's even correct) how do I know what to put in for my_local_computer?
Thanks!
You can automatically figure out where you're logged in from by checking the environment variables SSH_CONNECTION and/or SSH_CLIENT. SSH_CONNECTION for example shows the client address, the outgoing port on the client, the server address and the incoming port on the server. See section ENVIRONMENT in man ssh
So, if you want to copy a file from the server to the client from which you're logged in from, the following (which infers the client ip by taking the first part of SSH_CONNECTION) should work:
scp /path/to/file $(echo $SSH_CONNECTION | cut -f 1 -d ' '):/local/path/to/file
Andreas
You are on the right track! The man page for scp should tell you how to do what you want: http://linux.die.net/man/1/scp
If you are having trouble understanding the man page, then I will attempt to instruct you:
If you want to push a file from your local machine to a remote machine
scp /path/to/local/file testuser#remote-host:/path/to/where/you/want/to/put/file
If you want to pull a file from a remote machine to your local machine
scp testuser#remote-host:/path/to/file/you/want/to/pull /path/on/local/machine/to/place/file
If you are logged into a remote machine and want to push a file to your local machine (assuming you have the ability to scp to the local machine in the first place)
scp /path/on/remote/machine/to/file testuser#local-host:/path/on/local/machine/to/put/file
Now, to determine what your local-host address is, you can check the IP address of your local machine or if your local machine has been provided a DNS entry, you could use it.
I.E., scp ~/myfile testuser#192.168.1.10:/home/testuser/myfile OR scp ~/myfile testuser#my-host:/home/testuser/myfile
For the DNS entry, provided you are on a correctly configured network, you would not need a fully qualified domain. Otherwise, you would need to do something like testuser#my-host.example.com:/home/testuser/myfile
Maybe you can build a solution around this:
who | grep $USER
When run on the remote computer, it should give a hint where you connected form.

Resources