The idea behind using SSH (secure shell) falls when one is interested in sending files over the network in secure way. There are existing methods which will accomplish the task, but SSH is a cool one when one wants real security.
Here is the step to send files securely from your machine to the other.
1. install ssh client and ssh server using
sudo apt-get install openssh-client openssh-server
2. log into the server using the command
where username is the user at the server. This can be checked on local machine as ssh user@localhost
3. Now we can share files using the tool scp
to upload file use:
scp path/to/file/to/upload user@server:/path/to/host/directory
Say, to upload the file test.txt from local machine to server named someserver.com into directory /home/remote, then
scp /home/user/test.txt email@example.com:/home/remote
And to download file from the same server to local machine
scp firstname.lastname@example.org:/home/remote/test.txt /home/user/downloads
This one required logging every time with subsequent request of password. To setup a secure file transfer without password the way to go would be using public private combination between server and client.
Logging to SSH Server without password
Generating and using public private key
1. Creating Public Private key can be done using:
ssh-keygen -t dsa – or if you want to make rsa: ssh-keygen -t rsa
2. it will prompt you to where to put the file and the passkey for the files. take default file path. This would allow the creation of id_dsa (private key) and id_dsa.pub (public key) into the ssh directory. -> The directory would be into /home/user/.ssh/. The private key would retain with the generating server while the public key would be uploaded to the server where you would create the connection.
3. Make sure the following are available and not commented in
and from /etc/ssh/sshd_config
4. Make sure you have id_dsa, id_dsa.pub or rsa versions on .ssh folder
5. Copy the public key to the remote server using
scp /path/to/publickey user@server:/home/user/.ssh/ – where user is the authenticated user on the remote server
6. You will be asked for one last time your password for copying the file.
7. Log to remote server using your password
8. Navigate to /home/USER/.ssh
9. having the publicKey [it is the one you scp it, like id_rsa.pub or id_dsa.pub: cat publicKey >> authorized_keys
9. The file will now be added to the remote server’s authorized_keys. This will give you an access from your machine to the remote server without password – unless you want it to.
Make sure the file permission for authorized_keys is 600 and
for .ssh directory it is 700