sshpass Failed to Get a Pseudo Terminal in Windows 10 ubuntu linux bash - linux

Has anyone tried using sshpass in a windows 10 insider preview linux terminal?
It just returns this error
root#T430U:~# sshpass -p mypass ssh user#host
Failed to get a pseudo terminal: No such file or directory

Like it says here. You have to mount the pts directory:
m -rf /dev/ptmx
mknod /dev/ptmx c 5 2
chmod 666 /dev/ptmx
umount /dev/pts
rm -rf /dev/pts
mkdir /dev/pts
vim /etc/fstab
(added: none /dev/pts devpts defaults 0 0)
mount /dev/pts

Related

Device node in LXC is not accessible when connected via SSH

I have a problem where a physical hardware device passed through to an LXC container cannot be read from or written to when I am connected via SSH.
The device node of my physical hardware device looks like this:
myuser#myhost:~$ ls -la /dev/usb/hiddev0
crw-rw-rw- 1 root root 180, 0 Jul 30 10:27 /dev/usb/hiddev0
This is how I create and start my container:
myuser#myhost:~$ sudo lxc-create -q -t debian -n mylxc -- -r stretch
myuser#myhost:~$ sudo lxc-start -n mylxc
Then I add the device node to the LXC:
myuser#myhost:~$ sudo lxc-device -n mylxc add /dev/usb/hiddev0
Afterwards the device is available in the LXC and I can read from it after having attached to the LXC:
myuser#myhost:~$ sudo lxc-attach -n mylxc
root#mylxc:/# ls -la /dev/usb/hiddev0
crw-r--r-- 1 root root 180, 0 Aug 27 11:26 /dev/usb/hiddev0
root#mylxc:/# cat /dev/usb/hiddev0
����������^C
root#mylxc:/#
I then enable root access via SSH without a password:
myuser#myhost:~$ sudo lxc-attach -n mylxc
root#mylxc:/# sed -i 's/#\?PermitRootLogin.*/PermitRootLogin yes/g' /etc/ssh/sshd_config
root#mylxc:/# sed -i 's/#\?PermitEmptyPasswords.*/PermitEmptyPasswords yes/g' /etc/ssh/sshd_config
root#mylxc:/# sed -i 's/#\?UsePAM.*/UsePAM no/g' /etc/ssh/sshd_config
root#mylxc:/# passwd -d root
passwd: password expiry information changed.
root#mylxc:/# /etc/init.d/ssh restart
Restarting ssh (via systemctl): ssh.service.
root#mylxc:/# exit
When I connect via SSH now, the device node is there, but I cannot access it:
myuser#myhost:~$ ssh root#<lxc-ip-address>
root#mylxc:~# ls -la /dev/usb/hiddev0
crw-r--r-- 1 root root 180, 0 Aug 27 11:26 /dev/usb/hiddev0
root#mylxc:~# cat /dev/usb/hiddev0
cat: /dev/usb/hiddev0: Operation not permitted
In both cases (lxc-attach and ssh) I am the root user (verified via whoami), so this cannot be the problem.
Why am I not allowed to access the device when I am connected via SSH?
EDIT
In the meantime I found out that the error disappears when I call all the LXC initialization commands directly one after another in a script, i.e.:
sudo lxc-create -q -t debian -n mylxc -- -r stretch
sudo lxc-start -n mylxc
sudo lxc-device -n mylxc add /dev/usb/hiddev0
...
And then all the SSH configuration as described above. The device is correctly accessible via SSH then.
As soon as some time passes between lxc-start and lxc-device, the error appears, e.g.:
sudo lxc-create -q -t debian -n mylxc -- -r stretch
sudo lxc-start -n mylxc
sleep 1
sudo lxc-device -n mylxc add /dev/usb/hiddev0
...
Why is the timing relevant here? What happens during the first second within the LXC that makes the device become unaccessible?
With help from the lxc-users mailing list I found out that the restriction is intended. Access to devices has to be allowed explicitly in the LXC's config using their major/minor numbers:
lxc.cgroup.devices.allow = c 180:* rwm
The unrestricted access using lxc-attach seems to be some bug in my case. Devices should never be accessible in the LXC if not explicitly allowed.

QEMU: /bin/sh: can't access tty; job control turned off

As a development environment for linux kernel, I'm using qemu with setting up initramfs as similar to what is shown here, with few additional executable. Basically, it uses busybox for creating minimal environment and package it up using cpio. Content of init is shown below.
$ cat init
mount -t proc none /proc
mount -t sysfs none /sys
echo -e "\nBoot took $(cut -d' ' -f1 /proc/uptime) seconds\n"
exec /bin/sh
Using following command to start VM:
qemu-system-x86_64 -kernel bzImage -initrd initramfs -append "console=ttyS0" -nographic
It throws following error:
/bin/sh: can't access tty; job control turned off
Although, system functions normal in most cases. But, I'm not able to create background process:
$ prog &
/bin/sh: can't open '/dev/null'
$ fg
/bin/sh: fg: job (null) not created under job control
Root of all problems seem to be not having access to tty. How can I fix this?
EDIT: Apart from Accepted answer, as a get around cttyhack of busybox can be used.
$cat init
#!/bin/sh
mount -t proc none /proc
mount -t sysfs none /sys
mknod -m 666 /dev/ttyS0 c 4 64
echo -e "\nBoot took $(cut -d' ' -f1 /proc/uptime) seconds\n"
setsid cttyhack sh
exec /bin/sh
From Linux From Scratch Chapter 6.8. Populating /dev
6.8.1. Creating Initial Device Nodes
When the kernel boots the system, it requires the presence of a few device nodes, in particular the console and null devices. Create these by running the following commands:
mknod -m 600 /dev/console c 5 1
mknod -m 666 /dev/null c 1 3
You should then continue with the steps in "6.8.2. Mounting tmpfs and Populating /dev". Note the <-- below, and I suggest you read the entire free LFS.
mount -n -t tmpfs none /dev
mknod -m 622 /dev/console c 5 1
mknod -m 666 /dev/null c 1 3
mknod -m 666 /dev/zero c 1 5
mknod -m 666 /dev/ptmx c 5 2
mknod -m 666 /dev/tty c 5 0 # <--
mknod -m 444 /dev/random c 1 8
mknod -m 444 /dev/urandom c 1 9
chown root:tty /dev/{console,ptmx,tty}

Grub configuration for liveCD

I need to create my custom linux liveCD. I used this perfect guide to do this.
In few words: I took linux Mint liveCD, mount it, unpack filesysetm.squashfs, edit it with chroot and pack everything back to iso.
I faced with a problem when tried customize grub settings. For example, I want to set GRUB_TIMEOUT to zero. I can edit grub config file, but i can't run update-grub.
voronwe#sul $ sudo chroot edit
sul # mount -t proc none /proc
sul # mount -t sysfs none /sys
sul # mount -t devpts none /dev/pts
sul # export HOME=/root
sul # export LC_ALL=C
sul # update-grub
/usr/sbin/grub-probe: error: cannot find a device for / (is /dev mounted?).
And i can't mount boot:
sul # mount boot
mount: can't find boot in /etc/fstab or /etc/mtab
sul # cat /etc/fstab
# UNCONFIGURED FSTAB FOR BASE SYSTEM
sul # cat /etc/mtab
binfmt_misc /proc/sys/fs/binfmt_misc binfmt_misc rw,noexec,nosuid,nodev 0 0
none /proc proc rw 0 0
none /sys sysfs rw 0 0
none /dev/pts devpts rw 0 0
So, do anyone know how can grub configuration be update on liveCD?
I found the way.
There is a file isolinux/isolinux.cfg in the folder, where filesystem.squashfs was unpacked. I delete almost everything to get clear system boot. Minimal necessary settings in this file are:
default livelinux
timeout 0
label livelinux
kernel /casper/vmlinuz
append file=/cdrom/preseed/linuxmint.seed boot=casper initrd=/casper/initrd.lz quiet splash --
Were "timeout" is a GRUB_TIMEOUT * 10. So if you want to wait 1 second in boot menu you should write
timeout 10

Mount Squashfs as Root in initramfs Raspbian

I'm currently trying to make my raspbian boot from a squashFS image through initramfs.
The squashfs image is on file system /dev/mmcblk0p1, so I mount this prior to mounting the Image.
Unfortunately I'm stuck at mounting the SquashFS Image file.
I tried mounting through
mount -o loop
but I always get
mounting /dev/loop0 on /mnt/root failed: No such device
So I tried to mount it through loop manually. The problem is, that mounting the /dev/loop0 fails with the same Error as above.
This is my init so far:
#!/bin/busybox sh
# Mount the /proc and /sys filesystems.
mount -t proc none /proc
mount -t sysfs none /sys
#create loop devices
mknod /dev/loop0 b 7 0
mkdir /mnt/root
# Mount the boot partition
mount -o ro /dev/mmcblk0p1 /mnt/boot
sleep 5
# Mount the root FS with losetup
echo "Mounting with losetup"
losetup /dev/loop0 /mnt/boot/SYSTEM
mount /dev/loop0 /mnt/root -t squashfs
echo "Done"
#mount -o ro,loop -t squashfs /mnt/boot/SYSTEM /mnt/root
# Use Fallback mounting failed
if [ ! -e /mnt/root/home ]
then
echo "MOUNTING SDA1"
mount /dev/sda1 /mnt/root -t ext4
fi
# Clean up.
umount /proc
umount /sys
umount /mnt/boot
# Boot the real thing.
exec switch_root /mnt/root /sbin/init
Checking
losetup /dev/loop0
tells me, that the squashfs Image has been attached to loop0.
Does somebody know where to start?
I came across your question because I ran into the same thing today while building my own initramfs. I did some more digging and found this:
http://www.silas.net.br/doc.notes/unix/linux/busybox-troubleshooting.html
Then it dawned on me that I hadn't built squashfs into the kernel or loaded the module. After I did that, everything worked!
In case you haven't, make sure your kernel supports squashfs.

Ubuntu mount -t command

I use following command to mount "/dev/sdb1" to "/storage" directory:
mount -t ext3 /dev/sdb1 /storage
After run above command, I can use "df -h" can see it:
/dev/sdb1 147G 188M 140G 1% /storage
But after i restart the server, it disappear, and i have to run mount command again.
Is there a command that can keep the mount even if i restart the server?
Add the following line to your /etc/fstab file:
# device name mount point fs-type options dump-freq pass-num
/dev/sdb1 /storage ext3 defaults 0 0
You can run (as root):
echo "/dev/sdb1 /storage ext3 defaults 0 0" >> /etc/fstab
You need to add relevant information to /etc/fstab.

Resources