MARWAN docs NOC knowledge base
DocsGNU/Linux

GNU/Linux useful commands

Short GNU/Linux fixes and commands for servers: IP addresses, symlinks, root password reset, SSH key permissions and the floppy I/O error.

1. Add/remove an IP address#

To add/remove a single IPv4/IPv6 address from an interface, run:

ip addr <add/del> <youripaddress> dev <nameofinterface>

Examples:

ip addr add 192.0.2.10/24 dev ens32
ip addr del 2001:db8:f5:0:250:56ff:fe80:413f/64 dev ens32

These changes are lost at reboot. To make them permanent, use nmcli or nmtui on Rocky/Alma Linux, or /etc/network/interfaces on Debian.

Without -h, chown changes the file the link points to instead of the link itself:

chown -h user:group /path/to/link

3. Reset a lost root password on Rocky/Alma Linux or CentOS#

  1. Reboot and press e on the GRUB entry.
  2. At the end of the line starting with linux, add rd.break, then press Ctrl+X.
  3. In the emergency shell:
mount -o remount,rw /sysroot
chroot /sysroot
passwd
touch /.autorelabel   # SELinux relabels the files at next boot
exit
exit

The first boot after this takes longer while SELinux relabels the disk.

4. SSH: "Authentication refused: bad ownership or modes"#

sshd refuses keys when the home directory, .ssh or authorized_keys can be written by others. In /var/log/secure (or journalctl -u sshd) you see Authentication refused: bad ownership or modes for directory. Fix the owners and modes (here for root):

chown root:root /root /root/.ssh /root/.ssh/authorized_keys
chmod 755 /root
chmod 700 /root/.ssh
chmod 600 /root/.ssh/authorized_keys

If the permissions are right and keys still fail on a RHEL-like system, check the SELinux context: see Fix SSH key logins not working on RHEL like systems.

5. "print_req_error: I/O error, dev fd0, sector 0" on Debian or Ubuntu VMs#

The kernel probes a virtual floppy drive that doesn't exist. Remove the module and keep it from loading again:

rmmod floppy
echo "blacklist floppy" > /etc/modprobe.d/blacklist-floppy.conf
update-initramfs -u