Running sshfs fusermount after unshare -r - linux

We have sshfs installed and working so we can mount a remote directory with the command
sshfs user#remotemachine:dir mount_location
however if we try using this same working command after running an unshare -r we get the error:
fusermount: mount failed: Operation not permitted.
What could we do to run the sshfs mount after the unshare without it failing?

Related

Getting files from remote windows pc into linux pc using command line

Trying to copy files from remote windows pc into my local linux using shell script.
Can someone please tell me how this can be done?
You can use smbclient to connect to the windows shared directory:
smbclient -L <ip address> -U <windows user>
Alternatively, you can mount a shared directory using smb mount:
mkdir /mnt/local_share
sudo mount -t cifs //<ip address/<shared directory> /mnt/local_share

How to mount /proc in Docker Container

Why can't I mount the /proc device from the container during the build process?
If I run docker build -t test . with this Dockerfile:
FROM debian:stable-slim
RUN bash -c 'ls {/proc,/dev,/sys}'
I can see that all special devices are populated. But if I try this Dockerfile:
FROM debian:stable-slim
RUN bash -c 'ls {/proc,/dev,/sys}'
RUN mount --bind /proc /mnt
I get the following error:
mount: /mnt: permission denied.
The command '/bin/sh -c mount --bind /proc /mnt' returned a non-zero code: 32
I know it's possible to use --privileged mode in docker run, but my goal is not to access the host's /proc but to just mount the /proc device from container in a file system that I'm generating inside the container with debootstrap. So that I can install some packages, specifically default-jre.
My Docker Version: 20.10.8
EDIT
My goal is to create a custom live-cd like here, so I can't use the container's base OS.

Gio Mount Returns Different Outputs

I'm trying to make python script for mounting using Gio Module, however when i add my script to crontab or run it as a service, i only get filesystem root:
In shell:
gio mount -l
returns every mountable drive and volume,
however, when i run:
sudo gio mount -l
or
sudo -u myuser gio mount -l
i only get Filesystem root and floppy.
The difference i realized is,
sudo, or my script auto ran by system returns the volumes with type "GUnixVolume",
and just "gio mount -l" returns type GProxyDrive.
So what is the difference, and how can i detect external drives when my script is ran by system?

Why won't mount.cifs use my credential file?

I have a script that needs to mount a Windows share to a Linux box, run a script, then unmount it. Despite following the man page for mount.cifs the command fails to recognize the credential file.
I made sure file sharing packages were present:
sudo yum install samba-client samba-common cifs-utils
Created drive that network share will mount to
sudo mkdir /share/
Created the credential file
sudo vim /root/.cifs
.cifs file contents
username=uname
password=pword
Created my .sh file
sudo vim /usr/bin/scritp.sh
script.sh contents
#!bin/bash
mount.cifs //ipaddress/share /share/ -o credentials=/root/.cifs
<script which makes use of the share>
umount /share/
Made the script executable
sudo chmod u+x /usr/bin/script.sh
Tested script
cd /usr/bin
sudo ./script.sh
Despite having the credential file specified, I am still prompted for a password for root user (connecting to Windows share with no "root" user"
Output from running script:
Password for root#//ipaddress/share:
Can anyone figure out what I have done wrong? It seems consistent with all documentation I have read.
For some reason, modifying the script to the following worked:
mount -t cifs -o credentials=/root/.cifs //ipaddress/share /share/
cd /share/
./script.sh
umount /share/
Not sure why, since mount -t cifs just invokes mount.cifs, but if you are experiencing the same issue, that's how I finally got around it.

pivot_root device or resource busy

Produces the following command on Ubuntu 64bit on VMWare:
mount /dev/sda1 /newroot
cd /newroot
mkdir old-root
pivot_root . old-root
I get an error that I do not understand
pivot_root: device or resource busy
Any ideas?
I saw the same error when the new root directory is a plain directory. When the new root is a mount, it will be ok. A bind mount of a directory is ok too. Also need to make sure the root directory permission is 0755, and owned by the root user.
The related answer states that you need to umount /proc first. I do not see the same.
The host ubnutu is 16.04 and it pivots into 18.04. Used unshare -m -p -f /bin/bash, followed by pivot_root . old_root. The -f is necessary to avoid a memory allocation error.

Resources