Linux home file sharing

How to share files between a Linux and Windows computer

The easiest and most reliable way to share files between a Linux and Windows computer on the same local area network is to use the Samba file sharing protocol. All modern versions of Windows come with Samba installed, and Samba is installed by default on most distributions of Linux.

Create a shared folder on Windows

First, create a shared folder on your Windows machine.

  1. Open the Control Panel.
  2. Go to Network and Sharing Options.
  3. Go to Change Advanced Sharing Settings.
  4. Select Turn on Network Discovery and Turn on File and Print Sharing.

Now, create a new folder to share or choose an existing folder that you’d like to share.

  1. Right-click the folder and select Properties.
  2. Go to the Sharing tab.
  3. Above the Share button is the network name of the share you are creating. It should look like \\YOURCOMPUTERNAME\Users\YourUserName\ShareFolderName. Make a note of this network name to use later on your Linux machine.
  4. Click Share.

Access a Windows shared folder from Linux, using Konqueror

Many Linux distributions use the KDE desktop environment and the Konqueror file manager/browser. If this is what you are using, you can follow these steps to access your Windows shared folder:

  1. Click the K menu icon.
  2. Select Internet ->Konqueror.
  3. In the Konqueror window that opens, click the Network Folders link, or type remote:/ in the address bar and press Enter .
  4. Click the Samba Shares icon.
  5. Click the icon of your Windows Home workgroup.
  6. Click the Workgroup icon.
  7. Click the icon for your computer.
  8. When prompted, enter the username and password for the Windows account that created the share.
  9. Click OK.

Access a Windows shared folder from Linux, using Nautilus

Many Linux distributions, especially those that use the GNOME desktop environment, use the Nautilus file manager. If this is what you’re using, you can follow these steps to access your Windows shared folder:

  1. Open Nautilus.
  2. From the File menu, select Connect to Server.
  3. In the Service type drop-down box, select Windows share.
  4. In the Server field, enter the name of your computer.
  5. Click Connect.

Alternatively, in the Nautilus address bar, you can type smb://ComputerName/ShareName and press Enter . For instance, when you created your Windows Share, if the share name was listed as:

Type smb://YOURCOMPUTERNAME/Users/YourUserName/ShareFolderName and press Enter . Note the smb: at the beginning; in Linux, use forward slashes instead of backslashes.

Access a Windows shared folder from Linux, using the command line

You can also access your Windows share from the Linux command line using the smbclient program.

  1. Open a terminal.
  2. Type smbclient at the command prompt.
  3. If you receive a «Usage:» message, this means smbclient is installed, and you can skip to the next step. If the command is not found, however, you need to install smbclient. Follow these steps to install it.

Источник

How do I share a folder with another Linux machine on the same home network?

I’m trying to share a folder on one Ubuntu machine with another Ubuntu machine on the same home network. When I right click on the folder and choose Sharing Options, it tells me I need to install Windows network sharing services in order to share folders. What does Windows have to do with this? I’m not trying to share with a Windows machine.

9 Answers 9

What does Windows have to do with this? I’m not trying to share with a Windows machine.

You’re right, this can be confusing. So let me try to clarify the terms first of all:

The way Windows shares files and printers is called SMB. The people from the SAMBA project have implemented all of Microsoft’s protocols and specifications for Linux. Ubuntu therefore supports the same sort of file sharing as Windows, which is called Samba.

You can use SAMBA to share files between Linux machines. In fact, you might prefer it in case you have, for example, have a friend over with their Windows computer.

Alternatively, you can use The Linux Way of sharing files, which is NFS (Network File System) — This answer to a previous question explains how to do it. (but it’s rather technical)

So, when the Sharing Options dialogue asks you to install the packages, you’re not actually installing any Microsoft software or anything like that. Go ahead and do it, it’s perfectly safe.

You can try to just enable sharing before you follow Salih Emin’s instructions; if it doesn’t work, you will get a simple warning, you can then do the steps Salih describes if needed. I have tried it on a freshly installed and up-to-date system, and I indeed needed to do this.

I find SSHFS to be native, stable and extremely fast. I have two xubuntu machines (18.04) sharing /home folders and an Intel NUC as ‘dropbox’ USB stick. All over sshfs.

UPDATE 2020-07-12: I found SSHFS for Windows. A clean beautiful GUI, zero config and works with the SSH keys from linux-machines.

Here’s how to set this up sshfs and automatically reconnecting after a reboot using fstab without having to provide a password. A big thank you to serverfault user kubanczyk for how to reconnect after a remote suspend/resume.

I’ll use «Local machine — surfbox» for computer you’re connecting from, and «Remote machine — devbox» for the computer you’re connecting to.

Check your userID och groupID, they should both be 1000.

GroupID: id -g localuser UserID: id -u localuser

1. Get IP-adresses of your Local & Remote Machines.

I’ll use 192.168.1.150 for Local Machine (‘surfbox’) and 192.168.1.151 for Remote Machine (‘devbox’)

2. Install packages on Local and Remote Machines

3. Create a group fuse and add localuser to it

Create group: sudo groupadd fuse

Add localuser to the group: sudo usermod -a -G fuse $user

4. Enable «allow_other» in fuse config

We will need this option when mounting in fstab

Edit /etc/fuse.conf with your command line editor. Remove the hashtag before user_allow_other and save.

5. Generate SSH keys on Local Machine

Do not provide a password when prompted. Just press Enter to leave blank.

ssh-keygen -t rsa -C youremail@example.com

Keys are stored in Local machine home directory /.ssh folder

6. Transfer your Local machine public SSH key to the Remote machine

You will be prompted for password for Remote user on Remote machine. Local machine public key is now added to the file

/.ssh/authorized_keys on Remote machine.

7. Create a directory on Local machine /mnt folder where you will mount the Remote machine /home folder.

Choose any name which makes sense for your Remote machine.

sudo mkdir /mnt/devboxhome

8. Mount the Remote machine /home directory from terminal

Syntax for sshfs is

sshfs [user@]host:[directory] mountpoint [options]

sudo sshfs [remoteuser]@192.168.1.151:/home/[remoteuser] /mnt/devboxhome -o allow_other,default_permissions -o identityfile=/home/[localuser]/.ssh/id_rsa

example: assuming «steve» is the username on both Local and Remote machines

sudo sshfs steve@192.168.1.151:/home/steve /mnt/devboxhome -o allow_other,default_permissions -o identityfile=/home/steve/.ssh/id_rsa

Since you have transferred the public RSA key to Remote machine you should not be prompted for remoteuser password.

You will get a warning that the machine is not trusted and prompted if it should be added. Add the Remote machine as trusted.

9. Verify: Browse Remote Machine /home directory

In terminal on Local machine you can now list Remote machine /home directory under /mnt/devboxhome

cd /mnt/devboxhome ls

or use Nautilus to browse the directory. Great.

10. Enable reconnect after reboot

We will add an entry in /etc/fstab to make this happen. You will need your Local machine userid och groupid — see intro if you missed this. Edit /etc/fstab with your command line editor and add these two lines at the end of /etc/fstab

# Mount devbox at boot remoteuser@192.168.1.151:/home/[remoteuser]/ /mnt/devboxhome fuse.sshfs default_permissions,user,delay_connect,reconnect,ServerAliveInterval=15,ServerAliveCountmax=3,allow_other,identityfile=/home/[localuser]/.ssh/id_rsa,idmap=user,uid=1000,gid=1000 0 0

  • delay_connect makes the kernel wait until the network is up until it tries to mount the directory on Remote machine.
  • Since we are running as root during boot we have to specify the keyfile which is stored in localuser home directory.
  • allow_other — users other than the one doing the actual mounting can access the mounted filesystem.
  • idmap=user — only translate UID of connecting user
  • reconnect, ServerAliveInterval, ServerAliveCountMax — ssh sends keep-alive pings. If ServerAliveCountMax consecutive pings fail, reconnect.

A user logging in as steve on Local and Remote machines would have:

steve@192.168.1.151:/home/steve/ /mnt/devboxhome fuse.sshfs default_permissions,user,delay_connect,reconnect,ServerAliveInterval=15,ServerAliveCountmax=3,allow_other,identityfile=/home/steve/.ssh/id_rsa,idmap=user,uid=1000,gid=1000 0 0

IMPORTANT: a slash after remote directory: steve@192.168.1.151:/home/steve/

save /etc/fstab and .

11. Reboot

You should now be able to access Remote machine /home directory in the Local machine /mnt/devboxhome In Nautilus you can drag this folder to the Places bar

12. Repeat

Go through the same steps again on Remote machine to make the /home directory of Local machine shared.

Источник

Linux File Sharing Over Network Computers Using scp And rsync

In this article, we will look at scp and rsync , two powerful Linux utilities for sharing files and folders across networks. scp allows you to simply copy directories or files from or to any remote destination, whereas rsync , in addition to simply copying files, also acts as a synchronising tool, synchronising changes between source and destination. The following discussion focuses on their application and the various parameters that can be used in conjunction with them to improve speed and security.

What Is SCP?

The SCP protocol is a network protocol that is based on the BSD RCP protocol. It allows file transfers over a network using Secure Shell (SSH). A client can use SCP to send files to another client or server on the same network. It can also connect to a server and request or download files. If a user wants to share multiple files across a network computer, there are two options. The user has the option of specifying each file in the command and then providing the destination path. The second method is for the user to save all of the files in one folder and share the entire folder across the network computer. Both methods are discussed further below. You are free to use whoever you want.

Install OpenSSH Server In Linux

For Linux data transfer over the network, OpenSSH is required. I discovered that it is not already installed in some Linux distributions, so the commands fail. Install OpenSSH server before you begin sharing files via SCP.

Install OpenSSH Server

For Debian or Ubuntu based Linux distributions –

Syntax – How To Share Files Over A Network Computer?

Example – If you want to share a file name “myMovieList.txt” to a remote host(192.168.1.102), you can use the following command based on the above syntax. SCP Linux File Sharing

To copy file from remote machine to your local machine

To copy multiple files, provide space separated list of files and at the last destination path SCP – Copy multiple files

Using SCP Parameters For More File Sharing Options

You can use scp command with certain optional parameters that help you in faster copying and/or secure data transfer.

r: To copy directory you have to use parameter r to recursively copy the contents.

​The r command makes it very simple to transfer multiple files contained in a single folder. It’s one of the best methods to do quick and secure Linux file sharing over network computers. ‘r’ Parameter to copy the folder to a host computer

For example to copy blogs folder to remote machine, you would use command –

P: To send out file on the machine with different port​By default, scp shares file over network computers through port 22. In many cases, you would want to use another port then you can P parameter to use another port for folder sharing. ‘P’ Parameter to share files on host computer through a different port

c: Change Encryption algorithm by default, scp uses Triple-DES cipher to encrypt data before transferring it. You can use other ciphers like blowfish (which has higher performance over default one). ‘c’ Change Encryption Algorithm

C: To transfer even faster you can use compression parameter that would compress the data while transferring and auto decompress it on the destination.

What Is rsync?

Rsync is useful for both sharing and synchronising files and folders. In contrast to SCP, rsync only transfers differences between source and destination files/folders. It is faster than SCP because it uses compression and decompression by default. It will save you a lot of time once you get used to it.

Install rsync In Linux

For Debian or Ubuntu based Linux distributions –

For Fedora based Linux distributions –

Syntax To Sync Folder Between Network Computers

With rsync user can synchronize two folders existing over network computers. To transfer/sync folder from local to the remote host, use the following command – Sync folder using rsync

​[a and r params preserve timestamp, owner, links, etc and recursively syncs the files respectively].​List of optional parameters are:

-z: compress data.
-a: preserve links, owner, timestamp, etc.
-r: recursive.
–progress: show progress while transferring.
–include and — exclude: include or exclude pattern or files. Example


only rsync files/folders starting with S.

— delete: delete the directory if it doesn’t exist at source but exists at the destination.
–max-size : max transfer size limit. [eg: –max-size=’2000k’]
— remove-source-files: remove files at source after sync
— bwlimit: limit bandwidth for transfer [–bwlimit=1000] (limit by 1000 bps)
If you are unsure of rsync command result, you can also do a dry run with the command : –dry-run.

Conclusion

Both Linux utilities are useful for sharing files between computers on a network. Because it transfers only differences and compressed data by default, rsync is more efficient. That’s all I’ve got for now. More information can be found on man pages. Please leave any suggestions, comments, or questions in the section below.

Источник

Читайте также:  Параметры базы данных windows
Оцените статью