date
int64
1,220B
1,719B
question_description
stringlengths
28
29.9k
accepted_answer
stringlengths
12
26.4k
question_title
stringlengths
14
159
1,533,026,883,000
I have a sda7, which is where the OS was installed. It has the file system of ext4 with 8GB free of 25GB (with a key also). Aside from that I also has a sda4 of type ntfs which was my old data partition in Windows. I've taken about 20GB/102GB from it in order to extend sda7. But it seems that I can neither extend nor shrink the sda7, so the 20GB is useless. Is there any way to extend the sda7 WITH and/or WITHOUT using an USB? I used GParted but haven't applied the operations yet
It's hard to answer this question without more information, but most likely the case is clear: As you pointed out, sda7 is the partition your system is installed on. You're probably running gparted from within that system now, so the partition is mounted and needed to run the system. Therefore you can't modify sda7, because you can't modify an ext4 filesystem while it's in use. That is called "online resizing" and is only supported by very few filesystems. You have to use gparted from another boot medium, e.g. a live disc, to resize your system partition while it is not mounted.
Mount space on Ubuntu [closed]
1,533,026,883,000
I am a apprentice openSUSE user. When I turn on my laptop one of my HDD partitions are not mounted by default, so I have to open the GUI and manually click to mount it. Is there a way to automatically mount this, from what I have read I can do it with cron job but any other solutions are accepted. linux-clwa:/ # cat /etc/fstab UUID=63d5d975-9cfe-4bfc-b71c-71079f582545 swap swap defaults 0 0 UUID=515127ed-50f2-4827-b410-f7e5e599d1b1 / btrfs defaults 0 0 UUID=515127ed-50f2-4827-b410-f7e5e599d1b1 /boot/grub2/i386-pc btrfs subvol=@/boot/grub2/i386-pc 0 0 UUID=515127ed-50f2-4827-b410-f7e5e599d1b1 /boot/grub2/x86_64-efi btrfs subvol=@/boot/grub2/x86_64-efi 0 0 UUID=515127ed-50f2-4827-b410-f7e5e599d1b1 /opt btrfs subvol=@/opt 0 0 UUID=515127ed-50f2-4827-b410-f7e5e599d1b1 /srv btrfs subvol=@/srv 0 0 UUID=515127ed-50f2-4827-b410-f7e5e599d1b1 /tmp btrfs subvol=@/tmp 0 0 UUID=515127ed-50f2-4827-b410-f7e5e599d1b1 /usr/local btrfs subvol=@/usr/local 0 0 UUID=515127ed-50f2-4827-b410-f7e5e599d1b1 /var/crash btrfs subvol=@/var/crash 0 0 UUID=515127ed-50f2-4827-b410-f7e5e599d1b1 /var/lib/libvirt/images btrfs subvol=@/var/lib/libvirt/images 0 0 UUID=515127ed-50f2-4827-b410-f7e5e599d1b1 /var/lib/mailman btrfs subvol=@/var/lib/mailman 0 0 UUID=515127ed-50f2-4827-b410-f7e5e599d1b1 /var/lib/mariadb btrfs subvol=@/var/lib/mariadb 0 0 UUID=515127ed-50f2-4827-b410-f7e5e599d1b1 /var/lib/mysql btrfs subvol=@/var/lib/mysql 0 0 UUID=515127ed-50f2-4827-b410-f7e5e599d1b1 /var/lib/named btrfs subvol=@/var/lib/named 0 0 UUID=515127ed-50f2-4827-b410-f7e5e599d1b1 /var/lib/pgsql btrfs subvol=@/var/lib/pgsql 0 0 UUID=515127ed-50f2-4827-b410-f7e5e599d1b1 /var/log btrfs subvol=@/var/log 0 0 UUID=515127ed-50f2-4827-b410-f7e5e599d1b1 /var/opt btrfs subvol=@/var/opt 0 0 UUID=515127ed-50f2-4827-b410-f7e5e599d1b1 /var/spool btrfs subvol=@/var/spool 0 0 UUID=515127ed-50f2-4827-b410-f7e5e599d1b1 /var/tmp btrfs subvol=@/var/tmp 0 0 UUID=515127ed-50f2-4827-b410-f7e5e599d1b1 /.snapshots btrfs subvol=@/.snapshots 0 0 UUID=F1D3-F389 /boot/efi vfat umask=0002,utf8=true 0 0 UUID=984161fa-2fbe-4519-a0f5-fb6c2a0856d6 /home xfs defaults 1 2
You can add them in the file /etc/fstab Here is an example : UUID=35ba5186-5e5a-41e7-80b7-5247d8e06d95 /backup auto nosuid,nodev,nofail 0 0
Automatically mounting a partition [duplicate]
1,533,026,883,000
Understaning the Linux Kernel says Modern Operating Systems says In the second figure, does each arrow pointed from "Disk partition" refer to a file system? According to the first figure, each such arrow should refer to a block group, instead of a file system. A file system can contain multiple block groups, and a partition can contain at most file system. Thanks.
The first figure shows an Ext2 partition. This means a disk partition that stores an Ext2 filesystem. It does not show the entire disk. It also shows the layout of a block group. The second figure shows the entire disk. It also shows "a possible file-system layout". This layout is different to the layout of Ext2. A disk may be divided into several disk "partitions". It may be divided according to a partition table stored at the start and/or end of the disk. A disk partition may be used to store a "filesystem". An Ext2 filesystem can contain multiple "block groups". "A possible file-system layout" might be simpler, and not use block groups at all. This second figure is such an example. The simpler layout - not using block groups - was used by the very first UNIX filesystem. This first filesystem was just called "FS". In BSD 4.2 (1983), the Fast File System (FFS) used "cylinder groups", which look the same as block groups. FFS is also called the Unix File System (UFS). Versions of it were adopted widely outside BSD. https://en.wikipedia.org/wiki/Unix_File_System#History_and_evolution You might look at a Ext2 or "FFS" filesystem and think it looks like multiple independent filesystems. However, block groups are not independent. The data blocks of a file can be placed in other block groups, if necessary. The reason for block groups is to keep associated data close together, i.e. the file's "i-node" and its data blocks. This can improve performance by reducing disk head movements. FAT32 filesystems (and earlier FAT filesystems) are similar to the old "FS", in the sense that they do not use block groups. The FAT layout is different in other ways, for example there are no "i-nodes".
Does this refer to a file system?
1,533,026,883,000
Manpage of pvcreate says pvcreate initializes a PV so that it is recognized as belonging to LVM, and allows the PV to be used in a VG. A PV can be a disk partition, whole disk, meta device, or loopback file. Why doesn't the following pvcreate command fail to mark a disk as PV then? $ sudo parted -l Model: ATA TOSHIBA MQ01ABF0 (scsi) Disk /dev/sda: 500GB Sector size (logical/physical): 512B/512B Partition Table: gpt Disk Flags: Number Start End Size File system Name Flags 1 1049kB 538MB 537MB fat32 EFI System Partition boot, esp 2 538MB 500GB 500GB ext4 $ sudo lvmdiskscan /dev/sda1 [ 512.00 MiB] /dev/sda2 [ <465.26 GiB] 0 disks 2 partitions 0 LVM physical volume whole disks 0 LVM physical volumes $ sudo pvcreate /dev/sda Device /dev/sda excluded by a filter. roaima wrote in https://unix.stackexchange.com/a/502428/674: You're trying to use the entire /dev/sda for a PV. But you've got (at least) two partitions on that disk (sda1 and sda2), so LVM is rightly refusing to honour your request. Does it mean that we can make a disk a PV by pvcreate, if and only if the disk has only one partition? In other words, we can't make a disk a PV by pvcreate, if and only if the disk has more than one partitions? Thanks.
You said yourself: A PV can be a disk partition, whole disk, meta device, or loopback file I don't understand your question. A PV can be a partition or a whole disk. Delete all partitions and you will be able to use the whole disk. If you don't want to use the whole disk, then use a partition instead. You should also know that one partition that covers the whole disk space could make less trouble. Please read this answer before you wipe your hdd: What is the best practice for adding disks in LVM.
We can make a disk a PV by `pvcreate`, if and only if the disk has only one partition?
1,533,026,883,000
Which Partition is required in Linux? a. /dev-partition b. /home-partition c. /swap-partition My answer was .a (/dev )
Answer: none of the above. But the question is ill-posed because: /dev is usually not a partition. In most modern Linux distributions, it's a virtual in-memory filesystem (tmpfs) managed by udev so that it dynamically reflects the devices that are actually present in the system. But you can have a Linux system with a static /dev directory and that directory does not need to be its own filesystem (it usually isn't in this case) but instead would be a regular directory off the root filesystem. /swap doesn't make sense. Linux systems are usually provisioned with swap space (which is usually a partition) but it's not required. And it's certainly not called /swap. As for /home, that, like /dev, need not be (and often isn't) a separate filesystem. Anyway, a is probably the answer they're looking for even though it's not correct, and it's probably what I would have answered if faced with that question and only those choices. So you will probably be marked right.
Exam question about Partitions [closed]
1,533,026,883,000
I created a Linux live environment similar to WinPE on USB disk A. I inserted USB disk B containing rootfs.tar.gz, bzImage, and Burning.sh into PC and used USB disk A to enter the live environment. However, I now realize that Burning.sh cannot be executed in the live environment and the following error is reported: bash: ./Burning.sh: cannot execute: required file not found. Content of Burning.sh #!/usr/bin/bash ###################################################################### # Author: madship_xk ###################################################################### current_path=$(pwd) #clear # First, Fdisk echo "**1************************************************************************" echo "**2************************************************************************" foo(){ #clear echo "**3************************************************************************" echo "**4************************************************************************" ###获取第二个磁盘的信息### #fdisk -l | grep Disk | awk '{FS=" "} {print $2}' | sed 's/:/ /g' > ./tmp.txt ls /dev/sda > ./tmp.txt hdstr=`awk 'NR==1 {print}' ./tmp.txt` echo "hdstr="${hdstr} rm ./tmp.txt echo "**5************************************************************************" echo "********** 1st Command: FDISK ***********" echo "********** Plese Follow the Introduction! ***********" echo "**6************************************************************************" fdisk ${hdstr} <<EOT 1>/dev/null 2>/dev/null || exit 1 d 1 d 2 d 3 d 4 d n p 1 +2G n p 2 w EOT echo "**7************************************************************************" echo "********** 2nd Command: PARTX ***********" echo "********** Please Follow the Introduction! ***********" echo "**8************************************************************************" partx ${hdstr} 1>/dev/null #sleep 1 ###判断mmcblk0### #if [[ ${hdstr} = '/dev/mmcblk0' ]] ; then # echo "emmc exists..." # hdstr=`printf "%sp" ${hdstr}` # b_mmcFlag="1" #else # echo "ssd exists..." # b_mmcFlag="0" #fi #echo ${hdstr} sleep 1 #clear echo "**9************************************************************************" echo "********** 3rd Command: FORMAT SDB1 ***********" echo "********** Please Follow the Introduction! ***********" echo "**10************************************************************************" hdstr1=`printf "%s1" ${hdstr}` echo ${hdstr1} sleep 5 mkfs.ext4 ${hdstr1} 1>/dev/null sleep 1 #clear echo "**11************************************************************************" echo "********** 4th Command: FORMAT SDB2 ***********" echo "********** Please Follow the Introduction! ***********" echo "**12************************************************************************" hdstr2=`printf "%s2" ${hdstr}` echo ${hdstr2} sleep 5 mkfs.ext4 ${hdstr2} 1>/dev/null sleep 1 #clear echo " " echo "**13************************************************************************" echo "********** 6th Command: MIRROR IMAGE FOR SDB1 ***********" echo "********** Please Follow the Introduction! ***********" echo "**14************************************************************************" mkdir /mnt/boot mount ${hdastr1} /mnt/boot 1>/dev/null sleep 5 grub-install --root-directory=/mnt /dev/sda --force cat > /mnt/boot/grub/grub.cfg <<EOF 1>/dev/null || exit 1 #Begin cfg set default=0 set timeout=5 set root=(hd0,1) menuentry "GNU/Linux, Test-6.4.0-rt" { linux /bzImage rw root=/dev/sda2 } EOF cp "${current_path}/bzImage" /mnt/boot umount /mnt/boot sleep 1 #clear echo "**15************************************************************************" echo "********** 7th Command: MIRROR IMAGE FOR SDB2 ***********" echo "********** Please Follow the Introduction! ***********" echo "**16************************************************************************" sleep 2 mount ${hdstr2} /mnt cp "${current_path}/rootfs.tar.gz" /mnt cd /mnt tar -vxf rootfs.tar.gz rm rootfs.tar.gz cd ~ umount /mnt sync #clear echo "**17************************************************************************" echo "********** 7th Command: MIRROR IMAGE FOR SDB2 ***********" echo "********** Please Follow the Introduction! ***********" echo "**18************************************************************************" } jumpa(){ echo "Please input \"BURN\" to go to start point" read INP #echo $INP if [[ $INP = 'BURN' ]] ; then echo "Going to Start POINT......" sleep 2 echo foo else echo jumpa fi } jumpa
I solved my problem by executing: dos2unix Burning.sh
Cannot run shell scripts in a Debian live environment that is made by debian-live-12.1.0-amd64-gnome.iso
1,533,026,883,000
Can I copy a windows partition with 30% actually used space from a MBR drive onto a UEFI drive even though the partition is half the size and will cut off the end of the copy? Will a windows startup repair fix the cut off partition? First drive sda1 Windows, sda2 ext2 boot, sda3 physical volume for opensuse Second drive sda1 uefi, sda2 opensuse physical volume, sda3 truncated Windows backup partition
It looks like a very bad idea.......unless you first convert the Windows to EFI like in this question https://askubuntu.com/questions/447686/how-to-boot-windows-8-from-a-legacy-mbr-partition-in-uefi-mode-via-grub I am not sure about Windows and how this is related to Unix & Linux, but if you are talking about dd command you can do something like this: sda2 = Windows partition (defragmented) sdb3 = Windows partition with half size on the destination dd if=/dev/sda2 of=/dev/sdb1 Yes it will stop when there is no more size available, and chkdsk will be able to fix that. (i am not 100% sure about chkdsk, but i see something like this before) EFI uses a special partition with some loader files, you must copy they to, to the EFI partition from the old HD to the newer hard drive.
dd restore windows from MBR to smaller partition after installing OpenSUSE in UEFI, no secure boot [closed]
1,533,026,883,000
I heard that a partition used to house logical partitions is called an extended partition. Can an extended partition originally be either a primary partition or a logical partition? Or must an extended partition originally be a primary partition, but not a logical partition? In other words, if you have an extended partition wherein you have several logical partitions, can you make one logical partition become an extended partition to create logical partitions recursively? Thanks.
You need to understand the partitions logic: You may have maximum of 4 primary or extended partitions on disk (MBR disks) You can have only one extended partition If you want more you must have extended partition and inside this partition create logical partitions. Think about extended partition as container of logical partitions. You can't have filesystem on extended partition. Maybe this Wikipedia page can give you more information about the subject EDIT1: You can't convert logical to extended (and continue recursively) because you have already one extended (where this logical is created)
Can an extended partition originally be either a primary partition or a logical partition? [closed]
1,308,291,986,000
If I use pubkey auth from e.g.: an Ubuntu 11.04 how can I set the ssh client to use only password auth to a server? (just needed because of testing passwords on a server, where I default log in with key) I found a way: mv ~/.ssh/id_rsa ~/.ssh/id_rsa.backup mv ~/.ssh/id_rsa.pub ~/.ssh/id_rsa.pub.backup and now I get prompted for password, but are there any offical ways?
Disable PubkeyAuthentication and also set PreferredAuthentications to password so that alternative methods like gssapi-with-mic aren't used: ssh -o PubkeyAuthentication=no -o PreferredAuthentications=password example.com You need to make sure that the client isn't configured to disallow password authentication.
How to force ssh client to use only password auth?
1,308,291,986,000
When you accidentally attempt to connect to the wrong server with password credentials is it possible for the administrator to read and log the password you used?
Simple put: yes More detail... If you connect to my machine then you don't know if I'm running a normal ssh server, or one that has been modified to write out the password being passed. Further, I wouldn't necessarily need to modify sshd, but could write a PAM module (eg using pam_script), which will be passed your password. So, yes. NEVER send your password to an untrusted server. The owner of the machine could easily have configured it to log all attempted passwords. (In fact this isn't uncommon in the infosec world; set up a honeypot server to log the passwords attempted)
Is your SSH password revealed when you attempt to connect to the wrong server?
1,308,291,986,000
I need to manually edit /etc/shadow to change the root password inside of a virtual machine image. Is there a command-line tool that takes a password and generates an /etc/shadow compatible password hash on standard out?
You can use following commands for the same: Method 1 (md5, sha256, sha512) openssl passwd -6 -salt xyz yourpass Note: passing -1 will generate an MD5 password, -5 a SHA256 and -6 SHA512 (recommended) Method 2 (md5, sha256, sha512) mkpasswd --method=SHA-512 --stdin The option --method accepts md5, sha-256 and sha-512 Method 3 (des, md5, sha256, sha512) As @tink suggested, we can update the password using chpasswd using: echo "username:password" | chpasswd Or you can use the encrypted password with chpasswd. First generate it using this: perl -e 'print crypt("YourPasswd", "salt", "sha512"),"\n"' Then later you can use the generated password to update /etc/shadow: echo "username:encryptedPassWd" | chpasswd -e The encrypted password we can also use to create a new user with this password, for example: useradd -p 'encryptedPassWd' username
Manually generate password for /etc/shadow
1,308,291,986,000
Let's say I create a user named "bogus" using the adduser command. How can I make sure this user will NOT be a viable login option, without disabling the account. In short, I want the account to be accessible via su - bogus, but I do not want it to be accessible via a regular login prompt. Searching around, it seems I need to disable that user's password, but doing passwd -d bogus didn't help. In fact, it made things worse, because I could now login to bogus without even typing a password. Is there a way to disable regular logins for a given a account? Note: Just to be clear, I know how to remove a user from the menu options of graphical login screens such as gdm, but these methods simply hide the account without actually disabling login. I'm looking for a way to disable regular login completely, text-mode included.
passwd -l user is what you want. That will lock the user account. But you'll still be able to su - user but you'll have to su - user as root. Alternatively, you can accomplish the same thing by prepending a ! to the user's password in /etc/shadow (this is all passwd -l does behind the scenes). And passwd -u will undo this.
Disable a user's login without disabling the account
1,308,291,986,000
In Linux I can create a SHA1 password hash using sha1pass mypassword. Is there a similar command line tool which lets me create sha512 hashes? Same question for Bcrypt and PBKDF2.
Yes, you're looking for mkpasswd, which (at least on Debian) is part of the whois package. Don't ask why... anthony@Zia:~$ mkpasswd -m help Available methods: des standard 56 bit DES-based crypt(3) md5 MD5 sha-256 SHA-256 sha-512 SHA-512 Unfortunately, my version at least doesn't do bcrypt. If your C library does, it should (and the manpage gives a -R option to set the strength). -R also works on sha-512, but I'm not sure if its PBKDF-2 or not. If you need to generate bcrypt passwords, you can do it fairly simply with the Crypt::Eksblowfish::Bcrypt Perl module.
How to create SHA512 password hashes on command line
1,308,291,986,000
I notice a weird (well, according to me) thing about passwords. For example, if I type an incorrect password during login, there will be a few seconds' delay before the system tells me so. When I try to sudo with a wrong password I would also have to wait before the shell says "Sorry, try again". I wonder why it takes so long to "recognize" an incorrect password? This has been seen on several distributions I use (and even OSX), so I think it's not a distribution specific thing.
This is a security thing, it's not actually taking long to realize it. 2 vulnerabilities this solves: this throttles login attempts, meaning someone can't pound the system as fast as it can go trying to crack it (1M attempts a sec? I don't know). If it did it as soon as it verified your credentials were incorrect, you could use the amount of time it took for it to invalidate your credentials to help guess if part of your credentials were correct, dramatically reducing the guessing time. to prevent these 2 things the system just takes a certain amount of time to do it, I think you can configure the wait time with PAM ( see Michael's answer ). Security Engineering ( 3rd ed., Amazon | 2nd ed., free ) gives a much better explanation of these problems. See chapter 2 (PDF) — particularly §2.4 and §2.5.3.3.
Why is there a big delay after entering a wrong password?
1,308,291,986,000
I need to execute rsync, without it prompting me for password. I've seen in rsync manpage that it doesn't allow specifying the password as command line argument. But I noticed that it allows specifying the password via the variable RSYNC_PASSWORD. So I've tried exporting the variable, but rsync keeps asking me for password. export RSYNC_PASSWORD="abcdef" rsync [email protected]:/abc /def What am I doing wrong? Please consider: I understand that this is a bad idea from security aspect I must use only rsync, can't use other software I can't use key-based authentication I've already read many SE question, e.g.: how-to-pass-password-for-rsync-ssh-command @ stackoverflow.com rsync-cron-job-with-a-password @ superuser.com how-to-setup-rsync-without-password-with-ssh-on-unix-linux @ superuser.com In other words, I need to have the RSYNC_PASSWORD approach working! :-)
This password environment variable appears only to be used when using the rsync protocol: rsync rsync://[email protected]:/abc /def For this to work, you need to run rsync as a daemon as well (--daemon option), which is often done using inetd.conf. When using this protocol, abc should correspond to a target defined in /etc/rsyncd.conf. The user name should be present in a auth users line for this target, and a password file should be specified with the secrets file option. It is this secrets file that contains mappings between user names and passwords in the following format: username:password And it is this password that you can specify using the RSYNC_PASSWORD environment variable.
How to avoid password prompt with rsync (and without using public keys)?
1,308,291,986,000
I have MySQL password saved on a file foo.php, for example P455w0rd, when I try to use it: $ cat foo.php | grep '$dbpwd=' | cut -d '"' -f 2 | mysql -U root -p mydb -h friendserver Enter password: (holds) $ echo P455w0rd | mysql -u root -p mydb -h friendserver Enter password: (holds) Both option still ask for password, what's the correct way to send password from stdin?
You have to be very careful how you pass passwords to command lines as, if you're not careful, you'll end up leaving it open to sniffing using tools such as ps. The safest way to do this would be to create a new config file and pass it to mysql using either the --defaults-file= or --defaults-extra-file= command line option. The difference between the two is that the latter is read in addition to the default config files whereas with the former, only the one file passed as the argument is used. Your additional configuration file should contain something similar to: [client] user=foo password=P@55w0rd Make sure that you secure this file. Then run: mysql --defaults-extra-file=<path to the new config file> [all my other options]
How to pass password to mysql command line
1,308,291,986,000
I was looking down at my keyboard and typed my password in because I thought I had already typed my login name. I pressed Enter, then when it asked for the password I pressed Ctrl+c. Should I take some precautionary measure to make sure the password isn't stored in plain text somewhere or should I change the password? Also this was on a tty on ubuntu server 16.04 LTS.
The concern is whether your password is recorded in the authentication log. If you're logging in on a text console under Linux, and you pressed Ctrl+C at the password prompt, then no log entry is generated. At least, this is true for Ubuntu 14.04 or Debian jessie with SysVinit, and probably for other Linux distributions; I haven't checked whether this is still the case on a system with Systemd. Pressing Ctrl+C kills the login process before it generates any log entry. So you're safe. On the other hand, if you actually made a login attempt, which happens if you pressed Enter or Ctrl+D at the password prompt, then the username you entered appears in plain text in the authentication logs. All login failures are logged; the log entry contains the account name, but never includes anything about the password (just the fact that the password was incorrect). You can check by reviewing the authentication logs. On Ubuntu 14.04 or Debian jessie with SysVinit, the authentication logs are in /var/log/auth.log. If this is a machine under your exclusive control, and it doesn't log remotely, and the log file hasn't been backed up yet, and you're willing and able to edit the log file without breaking anything, then edit the log file to remove the password. If your password is recorded in the system logs, you should consider it compromised and you need to change it. Logs might leak for all kinds of reasons: backups, requests for assistance… Even if you're the only user on this machine, don't risk it. Note: I haven't checked whether Ubuntu 16.04 works differently. This answer may not be generalizable to all Unix variants and is certainly not generalizable to all login methods. For example OpenSSH does log the username even if you press Ctrl+C at the password prompt (before it shows the password prompt, in fact).
I accidentally typed my password into the login field, is it still secure?
1,308,291,986,000
I need to allow user martin to switch to user martin-test without password su - martin-test I think this can be configured in /etc/pam.d/su. There are already some lines in that file which can be uncommented. However, I don't like the idea of adding user martin to group wheel. I don't want to give martin any more privileges than to be able to switch to martin-test. I also do not want to use sudo. What would be the best way to do it, while keeping the privileges of user martin minimal?
Add the following lines underneath the pam_rootok.so line in your /etc/pam.d/su: auth [success=ignore default=1] pam_succeed_if.so user = martin-test auth sufficient pam_succeed_if.so use_uid user = martin These lines perform checks using the pam_succeed_if.so module. See also the Linux-PAM configuration file syntax to learn more about the auth lines. The first line checks whether the target user is martin-test. If it is nothing happens (success=ignore) and we can continue on the next line to check the current user. If it is not, the next line will be skipped (default=1) and we can continue on subsequent lines with the usual authentication steps. The second line checks whether the current user is martin or not, if it is then the system considers the authentication process as successful and returns (sufficient), if it is not, nothing happens and we continue on subsequent lines with the usual authentication steps. You can also restrict su to a group, here the group allowedpeople can su without a password: auth sufficient pam_succeed_if.so use_uid user ingroup allowedpeople
Allow user1 to "su - user2" without password
1,308,291,986,000
I noticed some time ago that usernames and passwords given to curl as command line arguments don't appear in ps output (although of course they may appear in your bash history). They likewise don't appear in /proc/PID/cmdline. (The length of the combined username/password argument can be derived, though.) Demonstration below: [root@localhost ~]# nc -l 80 & [1] 3342 [root@localhost ~]# curl -u iamsam:samiam localhost & [2] 3343 [root@localhost ~]# GET / HTTP/1.1 Authorization: Basic aWFtc2FtOnNhbWlhbQ== User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.15.3 zlib/1.2.3 libidn/1.18 libssh2/1.4.2 Host: localhost Accept: */* [1]+ Stopped nc -l 80 [root@localhost ~]# jobs [1]+ Stopped nc -l 80 [2]- Running curl -u iamsam:samiam localhost & [root@localhost ~]# ps -ef | grep curl root 3343 3258 0 22:37 pts/1 00:00:00 curl -u localhost root 3347 3258 0 22:38 pts/1 00:00:00 grep curl [root@localhost ~]# od -xa /proc/3343/cmdline 0000000 7563 6c72 2d00 0075 2020 2020 2020 2020 c u r l nul - u nul sp sp sp sp sp sp sp sp 0000020 2020 2020 0020 6f6c 6163 686c 736f 0074 sp sp sp sp sp nul l o c a l h o s t nul 0000040 [root@localhost ~]# How is this effect achieved? Is it somewhere in the source code of curl? (I assume it is a curl feature, not a ps feature? Or is it a kernel feature of some sort?) Also: can this be achieved from outside the source code of a binary executable? E.g. by using shell commands, probably combined with root permissions? In other words could I somehow mask an argument from appearing in /proc or in ps output (same thing, I think) that I passed to some arbitrary shell command? (I would guess the answer to this is "no" but it seems worth including this extra half-a-question.)
When the kernel executes a process, it copies the command line arguments to read-write memory belonging to the process (on the stack, at least on Linux). The process can write to that memory like any other memory. When ps displays the argument, it reads back whatever is stored at that particular address in the process's memory. Most programs keep the original arguments, but it's possible to change them. The POSIX description of ps states that It is unspecified whether the string represented is a version of the argument list as it was passed to the command when it started, or is a version of the arguments as they may have been modified by the application. Applications cannot depend on being able to modify their argument list and having that modification be reflected in the output of ps. The reason this is mentioned is that most unix variants do reflect the change, but POSIX implementations on other types of operating systems may not. This feature is of limited use because the process can't make arbitrary changes. At the very least, the total length of the arguments cannot be increased, because the program can't change the location where ps will fetch the arguments and can't extend the area beyond its original size. The length can effectively be decreased by putting null bytes at the end, because arguments are C-style null-terminated strings (this is indistinguishable from having a bunch of empty arguments at the end). If you really want to dig, you can look at the source of an open-source implementation. On Linux, the source of ps isn't interesting, all you'll see there is that it reads the command line arguments from the proc filesystem, in /proc/PID/cmdline. The code that generates the content of this file is in the kernel, in proc_pid_cmdline_read in fs/proc/base.c. The part of the process's memory (accessed with access_remote_vm) goes from the address mm->arg_start to mm->arg_end; these addresses are recorded in the kernel when the process starts and can't be changed afterwards. Some daemons use this ability to reflect their status, e.g. they change their argv[1] to a string like starting or available or exiting. Many unix variants have a setproctitle function to do this. Some programs use this ability to hide confidential data. Note that this is of limited use since the command line arguments are visible while the process starts. Most high-level languages copy the arguments to string objects and don't give a way to modify the original storage. Here's a C program that demonstrates this ability by changing argv elements directly. #include <stdlib.h> #include <stdio.h> #include <string.h> int main(int argc, char *argv[]) { int i; system("ps -p $PPID -o args="); for (i = 0; i < argc; i++) { memset(argv[i], '0' + (i % 10), strlen(argv[i])); } system("ps -p $PPID -o args="); return 0; } Sample output: ./a.out hello world 0000000 11111 22222 You can see argv modification in the curl source code. Curl defines a function cleanarg in src/tool_paramhlp.c which is used to change an argument to all spaces using memset. In src/tool_getparam.c this function is used a few times, e.g. by redacting the user password. Since the function is called from the parameter parsing, it happens early in a curl invocation, but dumping the command line before this happens will still show any passwords. Since the arguments are stored in the process's own memory, they cannot be changed from the outside except by using a debugger.
How does curl protect a password from appearing in ps output?
1,308,291,986,000
The ssh won't let me login, because account is locked. I want to unlock the user on my server for public key authorization over ssh, but do not enable password-ed login. I've tried: # passwd -u username passwd: unlocking the password would result in a passwordless account. You should set a password with usermod -p to unlock the password of this account. Auth log entries: Mar 28 00:00:00 vm11111 sshd[11111]: User username not allowed because account is locked Mar 28 00:00:00 vm11111 sshd[11111]: input_userauth_request: invalid user username [preauth]
Unlock the account and give the user a complex password as @Skaperen suggests. Edit /etc/ssh/sshd_config and ensure you have: PasswordAuthentication no Check that the line isn't commented (# at the start) and save the file. Finally, restart the sshd service. Before you do this, ensure that your public key authentication is working first. If you need to do this for only one (or a small number) of users, leave PasswordAuthentication enabled and instead use Match User: Match User miro, alice, bob PasswordAuthentication no Place at the bottom of the file as it is valid until the next Match command or EOF. You can also use Match Group <group name> or a negation Match User !bloggs As you mention in the comments, you can also reverse it so that Password Authentication is disabled in the main part of the config and use Match statements to enable it for a few users: PasswordAuthentication no . . . Match <lame user> PasswordAuthentication yes
How to unlock account for public key ssh authorization, but not for password authorization?
1,308,291,986,000
I need to password protect my PDF file(s), because I am going to send them through email and I want anyone who would view my PDF file(s) to be prompted for a password. How can I add a password to a PDF in Linux Mint 17.1?
You can use the program pdftk to set both the owner and/or user password pdftk input.pdf output output.pdf owner_pw xyz user_pw abc where owner_pw and user_pw are the commands to add the passwords xyz and abc respectively (you can also specify one or the other but the user_pw is necessary in order to prohibit opening). You might also want to ensure that encryption strength is 128 bits by adding (though currently 128 bits is default): .... encrypt_128bit If you cannot run pdftk as it is no longer in every distro, you can try qpdf. Using qpdf --help gives information on the syntax. Using the same "values" as for pdftk: qpdf --encrypt abc xyz 256 -- input.pdf output.pdf
How to set password for pdf files?
1,308,291,986,000
Suppose that I were using sha1pass to generate a hash of some sensitive password on the command line. I can use sha1pass mysecret to generate a hash of mysecret but this has the disadvantage that mysecret is now in the bash history. Is there a way to accomplish the end goal of this command while avoiding revealing mysecret in plain text, perhaps by using a passwd-style prompt? I'm also interested in a generalized way to do this for passing sensitive data to any command. The method would change when the sensitive data is passed as an argument (such as in sha1pass) or on STDIN to some command. Is there a way to accomplish this? Edit: This question attracted a lot of attention and there have been several good answers offered below. A summary is: As per @Kusalananda's answer, ideally one would never have to give a password or secret as a command-line argument to a utility. This is vulnerable in several ways as described by him, and one should use a better-designed utility that is capable of taking the secret input on STDIN @vfbsilva's answer describes how to prevent things from being stored in bash history @Jonathan's answer describes a perfectly good method for accomplishing this as long as the program can take its secret data on STDIN. As such, I've decided to accept this answer. sha1pass in my OP was just an example, but the discussion has established that better tools exist that do take data on STDIN. as @R.. notes in his answer, use of command expansion on a variable is not safe. So, in summary, I've accepted @Jonathan's answer since it's the best solution given that you have a well-designed and well-behaved program to work with. Though passing a password or secret as a command-line argument is fundamentally unsafe, the other answers provide ways of mitigating the simple security concerns.
If using the zsh or bash shell, use the -s option to the read shell builtin to read a line from the terminal device without it echoing it. IFS= read -rs VARIABLE < /dev/tty Then you can use some fancy redirection to use the variable as stdin. sha1pass <<<"$VARIABLE" If anyone runs ps, all they'll see is "sha1pass". That assumes that sha1pass reads the password from stdin (on one line, ignoring the line delimiter) when not given any argument.
Is there a way to pass sensitive data in bash using a prompt, for any command?
1,308,291,986,000
I want to change the password I assigned to root on my Debian webserver to something longer and more secure. How do I do that? I haven’t forgotten/lost the current password, I just want to change it.
Ah, use the passwd program as root: sudo passwd root Or, if you’re running as root already (which you shouldn’t be), just: passwd The root argument can be omitted, because when you execute passwd it defaults to the current user (which is root, as only root can change the root password).
How do you change the root password on Debian?
1,308,291,986,000
How do I configure my system to destroy all personal data when a certain password is entered? The motivation behind this being NSA stuff. I imagine there being three primary usage cases. At login, the entering of a predetermined password triggers destruction of user data. At system wake up. entering of a predetermined password triggers destruction of personal data. Entering any privileged command with a predetermined password triggers destruction of personal data. I know that something like dd if=/dev/urandom of=/dev/$HOME Should be adequate for data destruction. I don't know how to have that triggered by a certain password, however. Bonus points if it then permits a login while the data is being deleted.
Idea #1 - Hidden OS As an alternative method you could make use of TrueCrypt's "Hidden Operating System". This allows you to access a fake alternative OS when a certain password is used, rather than the primary OS. excerpt If your system partition or system drive is encrypted using TrueCrypt, you need to enter your pre-boot authentication password in the TrueCrypt Boot Loader screen after you turn on or restart your computer. It may happen that you are forced by somebody to decrypt the operating system or to reveal the pre-boot authentication password. There are many situations where you cannot refuse to do so (for example, due to extortion). TrueCrypt allows you to create a hidden operating system whose existence should be impossible to prove (provided that certain guidelines are followed — see below). Thus, you will not have to decrypt or reveal the password for the hidden operating system. Bruce Schneier covers the efficacy of using these (Deniable File Systems, so you might want to investigate it further before diving in. The whole idea of Deniable Encryption is a bit of a can of worms, so caution around using it in certain situations needs to be well thought out ahead of time. Idea #2 - Add a script to /etc/passwd You can insert alternative scripts to a user's entry in the /etc/passwd file. Example # /etc/passwd tla:TcHypr3FOlhAg:237:20:Ted L. Abel:/u/tla:/usr/local/etc/sdshell You could setup a user's account so that it runs a script such as /usr/local/etc/sdshell which will check to see what password was provided. If it's the magical password that triggers the wipe, it could begin this process (backgrounded even) and either drop to a shell or do something else. If the password provided is not this magical password, then continue on running a normal shell, /bin/bash, for example. Source: 19.6.1 Integrating One-Time Passwords with Unix
How to trigger a system self destruct with a certain password is entered
1,308,291,986,000
What's a good one-liner to generate an easily memorable password, like xkcd's correct horse battery staple or a Bitcoin seed? EDIT 1: This is not the same as generating a random string since random strings are not at all memorable. Compare to the obligatory xkcd...
First of all, install a dictionary of a language you're familiar with, using: sudo apt-get install <language-package> To see all available packages: apt-cache search wordlist | grep ^w Note: all installation instructions assume you're on a debian-based OS. After you've installed dictionary run: WORDS=5; LC_ALL=C grep -x '[a-z]*' /usr/share/dict/words | shuf --random-source=/dev/urandom -n ${WORDS} | paste -sd "-" Which will output ex: blasphemous-commandos-vasts-suitability-arbor To break it down: WORDS=5; — choose how many words you want in your password. LC_ALL=C grep -x '[a-z]*' /usr/share/dict/words — choose only words containing lowercase alphabet characters (it excludes words with ' in them or funky characters like in éclair). LC_ALL=C ensures that [a-z] in the regex won't match letter-like symbols other than lowercase letters without diacritics. shuf --random-source=/dev/urandom -n ${WORDS} — chose as many WORDS as you've requested. --random-source=/dev/urandom ensures that shuf seeds its random generator securely; without it, shuf defaults to a secure seed, but may fall back to a non-secure seed on some systems such as some Unix emulation layers on Windows. paste -sd "-" — join all words using - (feel free to change the symbol to something else). Alternatively you can wrap it in a function: #!/bin/bash function memorable_password() { words="${1:-5}" sep="${2:--}" LC_ALL=C grep -x '[a-z]*' /usr/share/dict/words | shuf --random-source=/dev/urandom -n ${words} | paste -sd "$sep" } or #!/bin/sh memorable_password() { words="$1" if [ -z "${words}" ]; then words=5 fi sep="$2" if [ -z "${sep}" ]; then sep="-" fi LC_ALL=C grep -x '[a-z]*' /usr/share/dict/words | shuf --random-source=/dev/urandom -n ${words} | paste -sd "$sep" } Both of which can be called as such: memorable_password 7 _ memorable_password 4 memorable_password Returning: skipped_cavity_entertainments_gangway_seaports_spread_communique evaporated-clashes-bold-presuming excelling-thoughtless-pardonable-promulgated-forbearing Bonus For a nerdy and fun, but not very secure password, that doesn't require dictionary installation, you can use (courtesy of @jpa): WORDS=5; man git | \ tr ' ' '\n' | \ egrep '^[a-z]{4,}$' | \ sort | uniq | \ shuf --random-source=/dev/urandom -n ${WORDS} | \ paste -sd "-"
One-liner to generate an easily memorable password? [duplicate]
1,308,291,986,000
I am trying to install Pass: the standard Unix password manager, however, when I try to add passwords to the appliation I get these errors gpg: Kelly's Passwords: skipped: No public key gpg: [stdin]: encryption failed: No public key GPG Public Keys? When I type in the command gpg --list-keys I get: /home/khays/.gnupg/pubring.gpg ------------------------------ pub 2048R/64290B2D 2012-11-05 uid Kelly Hays <[email protected]> sub 2048R/0DF57DA8 2012-11-05 I am a little lost of how to remedy this, any ideas?
How did you create the password store? pass init "Kelly's Passwords"? If so, this is wrong, you should have called pass init 64290B2D. And if then pass insert foo will fail with: gpg: fooo: skipped: public key not found gpg: [stdin]: encryption failed: public key not found then you have to trust your own key first (gpg --edit-key 64290B2D, trust, 5, save).
I try to add passwords to the "pass" password manager. But my attempts fail with "no public key" GPG errors. Why?
1,308,291,986,000
I'm setting up a few ubuntu boxes, and using opscode's chef as a configuration tool. It would be fairly easy to install public keys for each user on each of these servers, and disable password authentication. However, the users should also have sudo privileges though, which by default requires a password. If I want to use the users' public keys as a method of access management and allow the users sudo privileges, does that mean I should also set up the users with NOPASSWD: ALL in visduo, or is there a way that a user can change their own password if they only have public key authentication?
Sudo, in its most common configuration, requires the user to type their password. Typically, the user already used their password to authenticate into the account, and typing the password again is a way to confirm that the legitimate user hasn't abandoned their console and been hijacked. In your setup, the user's password would be used only for authentication to sudo. In particular, if a user's SSH key is compromised, the attacker would not be able to elevate to root privileges on the server. The attacker could plant a key logger into the account, but this key logger would be detectable by other users, and could even be watched for automatically. A user normally needs to know their current password to change it to a different password. The passwd program verifies this (it can be configured not to, but this is not useful or at all desirable in your scenario). However, root can change any user's password without knowing the old one; hence a user with sudo powers can change his own password without entering it at the passwd prompt by running sudo passwd $USER. If sudo is configured to require the user's password, then the user must have typed the password to sudo anyway. You can disable password authentication selectively. In your situation, you would disable password authentication in ssh, and possibly in other services. Most services on most modern unices (including Ubuntu) use PAM to configure authentication methods. On Ubuntu, the PAM configuration files live in /etc/pam.d. To disable password authentication, comment out the auth … pam_unix.so line in /etc/pam.d/common-auth. Furthermore, make sure you have PasswordAuthentication no in /etc/ssh/sshd_config to disable sshd's built-in password authentication. You may want to allow some administrative users to log in with a password, or to allow password authentication on the console. This is possible with PAM (it's pretty flexible), but I couldn't tell you how off the top of my head; ask a separate question if you need help.
Can a linux user change their password without knowing the current password?
1,308,291,986,000
Below is the process I took to create a user on bash in Linux. $ sudo useradd Alexandra $ sudo passwd Alexandra Enter new UNIX password: Enter new UNIX password: passwd: password updated successfully I understand that the password shouldn't be displayed for security purposes, but what I mean is, why do asterisks (or the characters I entered) not appear?
Because that's the way we do things in *nix land. :) It gives a little bit of extra security by not displaying a bunch of asterisks. That way, someone who sees your screen can't see the length of your password. But I must admit it is a little bit scary not getting any feedback when you're entering a password, especially if you've got a bad keyboard. So most GUI password dialog on *nix systems do give you some kind of feedback, e.g. using asterisks, or more commonly ⬤. And some even display each character as you type it, but then immediately replace it with a * or ⬤, but that's not so good if someone may be looking over your shoulder. Or if they have a device that can pick up & decode the video signal being sent from your computer to your monitor.
Why is the password I entered not visible?
1,308,291,986,000
I don't know if this is normal, but the thing is, let's say I have a Solaris user called gloaiza and its password is password2getin I'm logging into the server with PuTTY, I just put 192.168.224.100 and it prompts a windows asking for an user, so I type gloaiza, then it asks for a password and let's say I type password2geti by mistake, and it worked! I'm IN the server! Is that normal? It also works if I put something like password2getin2. I'm not a native English speaker, so, in case there's something you can't understand please ask me OS: Oracle Solaris 10 1/13
The operating system stores a hash of the password in /etc/shadow (or, historically, /etc/passwd; or a different location on some other Unix variants). Historically, the first widespread password hash was a DES-based scheme which had the limitation that it only took into account the first 8 characters of the password. In addition, a password hashing algorithm needs to be slow; the DES-based scheme was somewhat slow when it was invented but is insufficient by today's standards. Since then, better algorithms have been devised. But Solaris 10 defaults to the historical DES-based scheme. Solaris 11 defaults to an algorithm based on iterated SHA-256 which is up to modern standards. Unless you need historical compatibility with ancient systems, switch to the iterated SHA-256 scheme. Edit the file /etc/security/policy.conf and change the CRYPT_DEFAULT setting to 5 which stands for crypt_sha256. You may also want to set CRYPT_ALGORITHMS_ALLOW and CRYPT_ALGORITHMS_DEPRECATE. Once you've changed the configuration, run passwd to change your password. This will update the password hash with the currently configured scheme.
Solaris let me in with different password with the same 8 first characters
1,308,291,986,000
If we don't know the root password and don't have root access to the machine, how can we change the root password?
Here are a few ways I can think of, from the least intrusive to the most intrusive. Without Rebooting With sudo: if you have sudo permissions to run passwd, you can do: sudo passwd root Enter your password, then enter a new password for root twice. Done. Editing files: this works in the unlikely case you don't have full sudo access, but you do have access to edit /etc/{passwd,shadow}. Open /etc/shadow, either with sudoedit /etc/shadow, or with sudo $EDITOR /etc/shadow. Replace root's password field (all the random characters between the second and third colons :) with your own user's password field. Save. The local has the same password as you. Log in and change the password to something else. These are the easy ones. Reboot Required Single User mode: This was just explained by Renan. It works if you can get to GRUB (or your boot loader) and you can edit the Linux command line. It doesn't work if you use Debian, Ubuntu, and some others. Some boot loader configurations require a password to do so, and you must know that to proceed. Without further ado: Reboot. Enter boot-time password, if any. Enter your boot loader's menu. If single user mode is available, select that (Debian calls it ‘Recovery mode’). If not, and you run GRUB: Highlight your normal boot option. Press e to enter edit mode. You may be asked for a GRUB password there. Highlight the line starting with kernel or linux. Press e. Add the word ‘single’ at the end. (don't forget to prepend a space!) Press Enter and boot the edited stanza. Some GRUBs use Ctrl-X, some use b. It says which one it is at the bottom of the screen. Your system will boot up in single user mode. Some distributions won't ask you for a root password at this point (Debian and Debian-based ones do). You're root now. Change your password: mount / -o remount,rw passwd # Enter your new password twice at the prompts mount / -o remount,ro sync # some people sync multiple times. Do what pleases you. reboot and reboot, or, if you know your normal runlevel, say telinit 2 (or whatever it is). Replacing init: superficially similar to the single user mode trick, with largely the same instructions, but requires much more prowess with the command line. You boot your kernel as above, but instead of single, you add init=/bin/sh. This will run /bin/sh in place of init, and will give you a very early shell with almost no amenities. At this point your aim is to: Mount the root volume. Get passwd running. Change your password with the passwd command. Depending on your particular setup, these may be trivial (identical to the instructions for single user mode), or highly non-trivial: loading modules, initialising software RAID, opening encrypted volumes, starting LVM, et cetera. Without init, you aren't running dæmons or any other processes but /bin/sh and its children, so you're pretty literally on your own. You also don't have job control, so be careful what you type. One misplaced cat and you may have to reboot if you can't get out of it. Rescue Disk: this one's easy. Boot a rescue disk of your choice. Mount your root filesystem. The process depends on how your volumes are layered, but eventually boils down to: # do some stuff to make your root volume available. # The rescue disk may, or may not do it automatically. mkdir /tmp/my-root mount /dev/$SOME_ROOT_DEV /tmp/my-root $EDITOR /tmp/my-root/etc/shadow # Follow the `/etc/shadow` editing instructions near the top cd / umount /tmp/my-root reboot Obviously, $SOME_ROOT_DEV is whatever block device name is assigned to your root filesystem by the rescue disk and $EDITOR is your favourite editor (which may have to be vi on the rescue system). After the reboot, allow the machine to boot normally; root's password will be that of your own user. Log in as root and change it immediately. Other Ways Obviously, there are countless variations to the above. They all boil down to two steps: Get root access to the computer (catch-22 — and the real trick) Change root's password somehow.
How can we change root password?
1,308,291,986,000
I want to check, from the linux command line, if a given cleartext password is the same of a crypted password on a /etc/shadow (I need this to authenticate web users. I'm running an embedded linux.) I have access to the /etc/shadow file itself.
You can easily extract the encrypted password with awk. You then need to extract the prefix $algorithm$salt$ (assuming that this system isn't using the traditional DES, which is strongly deprecated because it can be brute-forced these days). correct=$(</etc/shadow awk -v user=bob -F : 'user == $1 {print $2}') prefix=${correct%"${correct#\$*\$*\$}"} For password checking, the underlying C function is crypt, but there's no standard shell command to access it. On the command line, you can use a Perl one-liner to invoke crypt on the password. supplied=$(echo "$password" | perl -e '$_ = <STDIN>; chomp; print crypt($_, $ARGV[0])' "$prefix") if [ "$supplied" = "$correct" ]; then … Since this can't be done in pure shell tools, if you have Perl available, you might as well do it all in Perl. (Or Python, Ruby, … whatever you have available that can call the crypt function.) Warning, untested code. #!/usr/bin/env perl use warnings; use strict; my @pwent = getpwnam($ARGV[0]); if (!@pwent) {die "Invalid username: $ARGV[0]\n";} my $supplied = <STDIN>; chomp($supplied); if (crypt($supplied, $pwent[1]) eq $pwent[1]) { exit(0); } else { print STDERR "Invalid password for $ARGV[0]\n"; exit(1); } On an embedded system without Perl, I'd use a small, dedicated C program. Warning, typed directly into the browser, I haven't even tried to compile. This is meant to illustrate the necessary steps, not as a robust implementation! /* Usage: echo password | check_password username */ #include <stdio.h> #include <stdlib.h> #include <pwd.h> #include <shadow.h> #include <sys/types.h> #include <unistd.h> int main(int argc, char *argv[]) { char password[100]; struct spwd shadow_entry; char *p, *correct, *supplied, *salt; if (argc < 2) return 2; /* Read the password from stdin */ p = fgets(password, sizeof(password), stdin); if (p == NULL) return 2; *p = 0; /* Read the correct hash from the shadow entry */ shadow_entry = getspnam(username); if (shadow_entry == NULL) return 1; correct = shadow_entry->sp_pwdp; /* Extract the salt. Remember to free the memory. */ salt = strdup(correct); if (salt == NULL) return 2; p = strchr(salt + 1, '$'); if (p == NULL) return 2; p = strchr(p + 1, '$'); if (p == NULL) return 2; p[1] = 0; /*Encrypt the supplied password with the salt and compare the results*/ supplied = crypt(password, salt); if (supplied == NULL) return 2; return !!strcmp(supplied, correct); } A different approach is to use an existing program such as su or login. In fact, if you can, it would be ideal to arrange for the web application to perform whatever it needs via su -c somecommand username. The difficulty here is to feed the password to su; this requires a terminal. The usual tool to emulate a terminal is expect, but it's a big dependency for an embedded system. Also, while su is in BusyBox, it's often omitted because many of its uses require the BusyBox binary to be setuid root. Still, if you can do it, this is the most robust approach from a security point of view.
How to check password with Linux?
1,308,291,986,000
How can I hide a password in shell scripts? There are a number of scripts that are accessing database. If we open the script others also aware the username and password. So if anyone knows how to hide please let me know. I have one way: place the password in a file and make the file as hidden and no one going to access the file (change the permissions and use the file in script while going to accessing database).
First, as several people have already said, keeping the credentials separate from the script is essential. (In addition to increased security, it also means that you can re-use the same script for several systems with different credentials.) Second, you should consider not only the security of the credentials but also the impact if/when those credentials are compromised. You shouldn't have just one password for all access to the database, you should have different credentials with different levels of access. You could, for instance, have one DB user that has the ability to perform a search in the database - that user should have read-only access. Another user may have permission to insert new records, but not to delete them. A third one may have permission to delete records. In addition to restricting the permissions for each account, you should also have restriction on where each account can be used from. For instance, the account used by your web server should not be allowed to connect from any other IP address than that of the webserver. An account with full root permissions to the database should be very restricted indeed in terms of where it may connect from and should never be used other than interactively. Also, consider using stored procedures in the database to restrict exactly what can be done by each account. These restrictions need to be implemented on the DB-server side of the system so that even if the client-side is compromised, the restrictions cannot be altered from it. (And, obviously, the DB server needs to be protected with firewalls etc in addition to the DB configuration...) In the case of a DB account that is only permitted limited read-only access, and only from a particular IP address, you might not need any further credentials than that, depending on the sensitivity of the data and the security of the host the script is being run from. One example may be a search form on your web site, which can be run with a user that is only allowed to use a stored procedure which extracts only the information that will be presented on the web page. In this case, adding a password does not really confer any extra security, since that information is already meant to be public, and the user can't access any other data that would be more sensitive. Also, make sure that the connection to the database is made using TLS, or anybody listening on the network can get your credentials. Third, consider what kind of credentials to use. Passwords are just one form, and not the most secure. You could instead use some form of public/private key pair, or AD/PAM or the like. Fourth, consider the conditions under which the script will be run: If it is run interactively, then you should enter the password, or the password to the private key, or the private key, or be logged in with a valid Kerberos ticket, when you run it - in other words, the script should get its credentials directly from you at the time that you run it, instead of reading them from some file. If it is run from a webserver, consider setting up the credentials at the time when you start the webserver. A good example here is SSL certificates - they have a public certificate and a private key, and the private key has a password. You may store the private key on the web server, but you still need to enter the password to it when you start Apache. You could also have the credentials on some kind of hardware, such as a physical card or an HSM, that can be removed or locked once the server is started. (Of course, the downside to this method is that the server can't restart on its own if something happens. I would prefer this to the risk of having my system compromised, but your mileage may vary...) If the script is being run from cron, this is the hard part. You don't want to have the credentials lying around anywhere on your system where someone can access them - but you do want to have them lying around so that your script can access them, right? Well, not quite right. Consider exactly what the script is doing. What permissions does it need on the database? Can it be restricted so that it doesn't matter if the wrong person connects with those permissions? Can you instead run the script directly on the DB server that nobody else has access to, instead of from the server that does have other users? If, for some reason that I can't think of, you absolutely must have the script running on an insecure server and it must be able to do something dangerous/destructive... now is a good time to re-think your architecture. Fifth, if you value the security of your database, you should not be running these scripts on servers that other people have access to. If someone is logged in on your system, then they will have the possibility to get at your credentials. For instance, in the case of a web server with an SSL certificate, there is at least a theoretical possibility of someone being able to gain root and access the httpd process's memory area and extract the credentials. There has been at least one exploit in recent times where this could be done over SSL, not even requiring the attacker to be logged in. Also, consider using SELinux or AppArmor or whatever is available for your system to restrict which users can do what. They will make it possible for you to disallow users to even try to connect to the database, even if they do manage to gain access to the credentials. If all this sounds like overkill to you, and you can't afford or don't have the time to do it - then, in my (arrogant and elitist) opinion, you should not be storing anything important or sensitive in your database. And if you're not storing anything important or sensitive, then where you store your credentials is also not important - in which case, why use a password at all? Lastly, if you absolutely cannot avoid storing some kind of credentials, you could have the credentials read-only and own by root and root could grant ownership on an exceedingly temporary basis when requested to do so by a script (because your script should not be run as root unless absolutely necessary, and connecting to a database does not make it necessary). But it's still not a good idea.
Hiding Password in Shell Scripts
1,308,291,986,000
How can one read passwords in bash scripts in such a way that tools do not show it on a terminal? (Changing font to black-on-black is easily worked around by copy & paste, so it's not solution.)
From help read: -s do not echo input coming from a terminal For example, to prompt the user and read an arbitrary password into the variable passwd, IFS= read -s -p 'Password please: ' passwd
Reading passwords without showing on screen in Bash Scripts
1,308,291,986,000
I have just started to use Scientific Linux (7.0) (although I assume this question might be distribution neutral..). The kernel version is 3.10.0-123.20.1.el7.x86_64. Coming back to my question. I switched to root account and from there created an new user account test-account using the command adduser test-account. It didn't prompt me for a password neither did I use the option to provide password. So I guess it's a "without password" account. I can login into this account from root account - which I suppose I'd be able to without providing password even if the test account had a password. However when I try to login into this(test-account) from a third account - it prompts me for password. And just pressing Enter doesn't work. Is it possible to login into this account from a non-root account. Is there a way (without switching to root or using sudo) ?
By default on enterprise GNU/Linux and its derivatives, the adduser command creates a user which is disabled until you explicitly specify a password for that user. Here is an example on CentOS 6.5, which should be the same as Scientific Linux. $ sudo adduser test $ sudo grep test /etc/shadow test:!!:123456:0:99999:7::: that's because in the /etc/shadow file, the password field is !!, as you can see in the example. Once you run passwd for this account, it will change the user's password and allow the user to be able to login. So what you should be able to do is the following to have a user without a password, simply create an account then delete the password. $ sudo adduser test $ sudo passwd -d test Removing password for user test. passwd: Success $ su test $ whoami test now any user should be able to use su and login as the user test in my example. You will not have to use sudo to login as the account. Although this is possible and you can have an account without a password, it is not advised. If you simply set the password for the user, you should be allowed to login. $ sudo passwd test [sudo] password for <YOURACCOUNT>: Changing password for user test. New password: Retype new password: passwd: all authentication tokens updated successfully.
User without a password - how can one login into that account from a non-root account
1,308,291,986,000
How is the random string M1uG*xgRCthKWwjIjWc*010iSthY9buc being detected as too simplistic/systematic for a password according to passwd and cracklib-check? Try it on your machine and see echo "M1uG*xgRCthKWwjIjWc*010iSthY9buc" | cracklib-check Note that this is not my password, but another randomly generated string from the same random password generator that produces the same result.
Since cracklib is open source, the answer can be found in the source code. "Too simplistic/systematic" means that there are too many characters that are preceded by one of their alphabetical neighbors. Hence "ab" or "ba" are considered bad, but "ac" or "ca" are OK since the b is omitted. Before this patch from 2010-03-02, it allows at most four characters that exhibit this trait. E.g., "bar12345" would fail, because the characters "a", "2", "3", "4" and "5" are alphabetical neighbors of the preceding characters. slm found out in his answer that M1uG*xgRCthKWwjIjWc*010iS was OK, while M1uG*xgRCthKWwjIjWc*010iSt is not. Let's analyze. Here are the characters that cracklib-check thinks are indications of a systematic password: M1uG*xgRCthKWwjIjWc*010iS ^^ ^^ which is below the max of four, but adding the t: M1uG*xgRCthKWwjIjWc*010iSt ^^ ^^ ^ pushes it above the limit, since T follows S (it appears the test is case insensitive). The patch changes the max limit so it depends on the total password length, to avoid false positives like this.
Why is this random password flagged saying it is too simplistic/systematic?
1,308,291,986,000
When did Unix move away from storing clear text passwords in passwd? Also, when was the shadow file introduced?
For the early history of Unix password storage, read Robert Morris and Ken Thompson's Password Security: A Case History. They explain why and how early Unix systems acquired most the features that are still seen today as the important features of password storage (but done better). The first Unix systems stored passwords in plaintext. Unix Third Edition introduced the crypt function which hashes the password. It's described as “encryption” rather than “hashing” because modern cryptographic terminology wasn't established yet and it used an encryption algorithm, albeit in an unconventional way. Rather than encrypt the password with a key, which would be trivial to undo when you have the key (which would have to be stored on the system), they use the password as the key. When Unix switched from an earlier cipher to the then-modern DES, it was also made slower by iterating DES multiple times. I don't know exactly when that happened: V6? V7? Merely hashing the password is vulnerable to multi-target attacks: hash all the most common passwords once and for all, and look in the password table for a match. Including a salt in the hashing mechanism, where each account has a unique salt, defeats this precomputation. Unix acquired a salt in Seventh Edition in 1979. Unix also acquired password complexity rules such as a minimum length in the 1970s. Originally the password hash was in the publicly-readable file /etc/passwd. Putting the hash in a separate file /etc/shadow that only the system (and the system administrator) could access was one of the many innovations to come from Sun, dating from around SunOS 4 in the mid-1980s. It spread out gradually to other Unix variants (partly via the third party shadow suite whose descendent is still used on Linux today) and wasn't available everywhere until the mid-1990s or so. Over the years, there have been improvements to the hashing algorithm. The biggest jump was Poul-Henning Kamp's MD5-based algorithm in 1994, which replaced the DES-based algorithm by one with a better design. It removed the limitation to 8 password characters and 2 salt characters and had increased slowness. See IEEE's Developing with open source software, Jan–Feb. 2004, p. 7–8. The SHA-2-based algorithms that are the de facto standard today are based on the same principle, but with slightly better internal design and, most importantly, a configurable slowness factor.
When did Unix stop storing passwords in clear text?
1,308,291,986,000
I would like to change a LUKS password. I want to remove my old password, but I would like to try out my new password before removing the original. I obviously know the old password. I would like to use the terminal not GUI. I have sensitive data on the drive and would rather not have to use my backup so I need the method to be safe.
In LUKS scheme, you have 8 "slots" for passwords or key files. First, check, which of them are used: cryptsetup luksDump /dev/<device> |grep BLED Then you can add, change or delete chosen keys: cryptsetup luksAddKey /dev/<device> [/path/to/<additionalkeyfile>, optional] cryptsetup luksChangeKey /dev/<device> -S 6 As for deleting keys, you have 2 options: a) delete any key that matches your entered password: cryptsetup luksRemoveKey /dev/<device> b) delete a key in specified slot: cryptsetup luksKillSlot /dev/<device> 6
How do I change a LUKS password?
1,308,291,986,000
In /etc/shadow file there are encrypted password. Encrypted password is no longer crypt(3) or md5 "type 1" format. (according to this previous answer) Now I have a $6$somesalt$someveryverylongencryptedpasswd as entry. I can no longer use openssl passwd -1 -salt salt hello-world $1$salt$pJUW3ztI6C1N/anHwD6MB0 to generate encrypted passwd. Any equivalent like (non existing) .. ? openssl passwd -6 -salt salt hello-world
Python: python -c 'import crypt; print crypt.crypt("password", "$6$saltsalt$")' (for python 3 and greater it will be print(crypt.crypt(..., ...))) Perl: perl -e 'print crypt("password","\$6\$saltsalt\$") . "\n"'
/etc/shadow : how to generate $6$ 's encrypted password? [duplicate]
1,308,291,986,000
If I do the following: sudo su - //enter password exit exit //login again straight away sudo su - The second invocation of sudo does not request a password because even though I have logged out again, I am still within some time limit meaning that I do not need to be prompted for my password again. Because I am trying out some new privs to make sure they work, this is really slowing me down while I wait for the timeout to happen. Is there a command I can run to reset the timeout? I don't want to change the timeout or affect other users, by the way!
sudo -k Will kill the timeout timestamp. You can even put the command afterwards, like sudo -k test_my_privileges.sh From man sudo: -K The -K (sure kill) option is like -k except that it removes the user's time stamp entirely and may not be used in conjunction with a command or other option. This option does not require a password. -k When used by itself, the -k (kill) option to sudo invalidates the user's time stamp by setting the time on it to the Epoch. The next time sudo is run a password will be required. This option does not require a password and was added to allow a user to revoke sudo permissions from a .logout file. When used in conjunction with a command or an option that may require a password, this option will cause sudo to ignore the user's cached credentials. As a result, sudo will prompt for a password (if one is required by the security policy) and will not update the user's cached credentials. You can also change it permanently. From man sudoers: timestamp_timeout Number of minutes that can elapse before sudo will ask for a passwd again. The timeout may include a fractional component if minute granularity is insufficient, for example 2.5. The default is 5. Set this to 0 to always prompt for a password. If set to a value less than 0 the user's timestamp will never expire. This can be used to allow users to create or delete their own timestamps via sudo -v and sudo -k respectively.
Forcing sudo to prompt for a password
1,308,291,986,000
I tried writing a shell script which can do automatic login into a ssh server using password which is mentioned in the script. I have written the following code: set timeout 30 /usr/bin/ssh -p 8484 [email protected] expect { "[email protected]'s password" { send "password\r" } } This code is not running properly, still it is asking for the password. Can somebody please help me in solving this
I once wrote an expect script to log in to a ssh server (like your case) and my script was something like this: #!/usr/bin/expect spawn ssh [email protected] expect "password" send "MyPassword\r" interact I think maybe the interact is missing in your script.
Shell Script for logging into a ssh server
1,308,291,986,000
Why do people fear writing passwords in the command line? The history file is located in ~/.history, so it's available only to the user who executed the commands (and root).
Command lines are not just available in history. They are also available, for example, in the output of ps -ocmd or through the /proc filesystem. (/proc/<pid>/cmdline) which is where ps reads them. Also, users' home directories are often world- or group- readable; you can make the history file only user-readable, but that might not survive deletion and recreation.
Why shouldn't someone use passwords in the command line?
1,308,291,986,000
I used the 'useradd' command to create a new account, but I did so without specifying the password. Now, when the user tries to log in, it asks him for a password. If I didn't set it up initially, how do I set the password now?
Easiest way to do this from the command line is to use the passwd command with root privileges. passwd username From man 1 passwd NAME passwd - update user's authentication token SYNOPSIS passwd [-k] [-l] [-u [-f]] [-d] [-n mindays] [-x maxdays] [-w warndays] [-i inactivedays] [-S] [--stdin] [username] DESCRIPTION The passwd utility is used to update user's authentication token(s). After you set the user password, you can force the user to change it on next login using the chage command (also with root privileges) which expires the password. chage -d 0 username When the user successfully authenticates with the password you set, the user will automatically be prompted to change it. After a successful password change, the user will be disconnected, forcing re-authentication with the new password. See man 1 chage for more information on password expiry.
How do I set the password of a new user after the account has already been created?
1,308,291,986,000
I would like to start a service using a systemd unit file. This service requires a password to start. I don't want to store the password in plaintext in the systemd unit file, because it is world-readable. I also don't want to provide this password interactively. If I were writing a normal script for this, I would store the credentials in a file owned by root with restricted permissions (400 or 600), and then read the file as part of the script. Is there any particular systemd-style way to do this, or should I just follow the same process as I would in a regular shell script?
There are two possible approaches here, depending on your requirements. If you do not want to be prompted for the password when the service is activated, use the EnvironmentFile directive. From man systemd.exec: Similar to Environment= but reads the environment variables from a text file. The text file should contain new-line-separated variable assignments. If you do want to be prompted, you would use one of the systemd-ask-password directives. From man systemd-ask-password: systemd-ask-password may be used to query a system password or passphrase from the user, using a question message specified on the command line. When run from a TTY it will query a password on the TTY and print it to standard output. When run with no TTY or with --no-tty it will use the system-wide query mechanism, which allows active users to respond via several agents
Is there a typical way to pass a password to a Systemd Unit file?
1,308,291,986,000
─[$] cat ~/.gitconfig [user] name = Shirish Agarwal email = [email protected] [core] editor = leafpad excludesfiles = /home/shirish/.gitignore gitproxy = \"ssh\" for gitorious.org [merge] tool = meld [push] default = simple [color] ui = true status = auto branch = auto Now I want to put my git credentials for github, gitlab and gitorious so each time I do not have to lookup the credentials on the browser. How can this be done so it's automated ? I am running zsh
Using SSH The common approach for handling git authentication is to delegate it to SSH. Typically you set your SSH public key in the remote repository (e.g. on GitHub), and then you use that whenever you need to authenticate. You can use a key agent of course, either handled by your desktop environment or manually with ssh-agent and ssh-add. To avoid having to specify the username, you can configure that in SSH too, in ~/.ssh/config; for example I have Host git.opendaylight.org User skitt and then I can clone using git clone ssh://git.opendaylight.org:29418/aaa (note the absence of a username there). Using gitcredentials If the SSH approach doesn't apply (e.g. you're using a repository accessed over HTTPS), git does have its own way of handling credentials, using gitcredentials (and typically git-credential-store). You specify your username using git config credential.${remote}.username yourusername and the credential helper using git config credential.helper store (specify --global if you want to use this setup everywhere). Then the first time you access a repository, git will ask for your password, and it will be stored (by default in ~/.git-credentials). Subsequent accesses to the repository will use the stored password instead of asking you. Warning: This does store your credentials plaintext in your home directory. So it is inadvisable unless you understand what this means and are happy with the risk.
how to set up username and passwords for different git repos?
1,308,291,986,000
We know that users' passwords are saved in /etc/passwd, but in an encrypted way, so even the root can't see them: jane:x:501:501::/home/jane:/bin/bash fred:x:502:502::/home/fred:/bin/bash As shown above, :x: represents the password. Is there a way (possible configuration) to save the password in the /etc/passwd in clear text and such that the root can see them?
The other two answers have told you—correctly!—that this is a Bad Idea™. But they've also told you its hard to do, requiring changing a bunch of programs. That's not true. It's very easy. You only need to change one or two configuration files. I feel its important to point this out, because you should be aware of it when logging into systems you don't control. These won't actually put a plain-text password in /etc/passwd or /etc/shadow, it'll go into a different file. Note I haven't tested these, as I'd rather not have my password in plain text. Edit /etc/pam.d/common-password (to catch on password changed) or /etc/pam.d/common-auth (to catch on login) and add in … pam_exec expose_authtok log=/root/passwords /bin/cat Edit both of those, and switch from pam_unix to pam_userdb with crypt=none. Alternatively, you could put it only in common-password (leaving pam_unix as well) to just record passwords when they're changed. You could remove the shadow (as well as any strong hash options) option from pam_unix to disable the shadow file, and go back to traditional crypt passwords. Not plain text, but John the Ripper will fix that for you. For further details, check the PAM System Admin Guide. You could also edit the source code of PAM, or write your own module. You'd only need to compile PAM (or your module), nothing else.
How to make user passwords shown as a clear text in Linux?
1,308,291,986,000
If a person has root access to a particular RHEL machine, will they be able to retrieve the password of the other users?
TL;DR: No, password are stored as hashes which can (in general) not be recovered. Linux doesn't store plain-text passwords anywhere by default. They are hashed or otherwise encrypted through a variety of algorithms. So, in general, no, this isn't possible with stored data. If you have passwords stored somewhere other than the /etc/passwd database, they may be stored in a way that allows this. htpasswd files can contain wealy encrypted passwords, and other applications may store weaker hashes or plain text passwords for various (typically bad) reasons. Also, user configuration files may contain unencrypted passwords or weakly protected passwords for various reasons - fetchmail grabbing content from another service, .netrc, or simple automated things may include the password. If the passwords are hashed or encrypted with an older, weak algorithm (3DES, MD5) it would be possible to work out reasonably efficiently / cheaply what the password was - albeit through attacking the data rather than just reversing the transformation. (eg: things like http://project-rainbowcrack.com/ or http://www.openwall.com/john/) Since you are root it is also possible to attack the user password at another level - replace the login binary, or sudo, or part of PAM, etc, with something that will capture the password when it is entered. So, in specific, no, but in general having root access does make it easier to get at the users details through various side-channels.
can we know the password for the other users if we have root access?
1,308,291,986,000
I would like to password protect or encrypt a directory and all the files within it (for the whole directory tree below it). I do not want to bother the whole home directory, I want a specific directory with some files and folders in it. I would like to be able to encrypt the directory or decrypt it using a password. Command line would be nicest to use. I don't want to have to create a new file as an encrypted version and then, delete the previous ones which are the non-encrypted version.
Use encfs (available as a package on most distributions). To set up: mkdir ~/.encrypted ~/encrypted encfs ~/.encrypted ~/encrypted # enter a passphrase mv existing-directory ~/encrypted The initial call to encfs sets up an encrypted filesystem. After that point, every file that you write under ~/encrypted is not stored directly on the disk, it is encrypted and the encrypted data is stored under ~/.encrypted. The encfs command leaves a daemon running, and this daemon handles the encryption (and decryption when you read a file from under ~/encrypted). In other words, for files under ~/encrypted, actions such as reads and writes do not translate directly to reading or writing from the disk. They are performed by the encfs process, which encrypts and decrypts the data and uses the ~/.encrypted directory to store the ciphertext. When you've finished working with your files for the time being, unmount the filesystem so that the data can't be accessed until you type your passphrase again: fusermount -u ~/encrypted After that point, ~/encrypted will be an empty directory again. When you later want to work on these files again, mount the encrypted filesystem: encfs ~/.encrypted ~/encrypted # enter your passphrase This, again, makes the encrypted files in ~/.encrypted accessible under the directory ~/encrypted. You can change the mount point ~/encrypted as you like: encfs ~/.encrypted /somewhere/else (but mount the encrypted directory only once at a time). You can copy or move the ciphertext (but not while it's mounted) to a different location or even to a different machine; all you need to do to work on the files is pass the location of the ciphertext as the first argument to encfs and the location of an empty directory as the second argument.
Simplest way to password protect a directory and its contents without having to create new files?
1,308,291,986,000
In the current version of Raspian, I know it is possible to change the password of the current logged in user from the command line like so: sudo passwd which will then prompt the user to enter a new password twice. This will produce output like so: Changing password for pi. (current) UNIX password: Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully I was wondering if there is a possible way to change a password programmatically, like from a shell script. I'm trying to make a configuration script to deploy on my Raspberry Pis and I don't want to manually have to type in new passwords for them.
You're looking for the chpasswd command. You'd do something like this: echo 'pi:newpassword' | chpasswd # change user pi password to newpassword Note that it needs to be run as root, at least with the default PAM configuration. But presumably run as root isn't a problem for a system deployment script. Also, you can do multiple users at once by feeding it multiple lines of input.
Change Password Programmatically
1,424,016,937,000
I want to assign 2 passwords to a single account. What I want to know is 1) is this possible, and 2) what are the security implications of this? The reason I want to do this is because I'm currently busy with some local testing, and I thought it would be convenient in some specific situations. After some research I found something called PAM, but I'm struggling to find information on how installation / configuration works. I'm running Ubuntu 12.04.
You can write a small PAM module to accept several different (hardcoded) passwords for an account. Here's an example source code for such a module: // Compile with: // gcc -fPIC -shared -o pam_multipass.so pam_multipass.c -lpam -lssl -lcrypto // Install into /lib/security/ (or other location, depending on your distribution): // sudo install --mode=0755 --owner=root --group=root pam_multipass.so /lib/security/pam_multipass.so #define _GNU_SOURCE #include <stdio.h> #include <security/pam_modules.h> #include <security/pam_ext.h> #include <string.h> #include <openssl/sha.h> #define USERNAME "username" #define PASSWORD_HASH_1 "xxxxxxxx" #define PASSWORD_HASH_2 "xxxxxxxx" PAM_EXTERN int pam_sm_authenticate(pam_handle_t *pamh, int flags, int argc, const char **argv) { const char *username; char *password; unsigned char result[SHA256_DIGEST_LENGTH]; char hexstring[65]; // Get the username pam_get_user(pamh, &username, NULL); if (strcmp(username, USERNAME) != 0) { return PAM_IGNORE; // Not the user we're interested in } // Prompt for password if (pam_prompt(pamh, PAM_PROMPT_ECHO_OFF, &password, "%s", "Password: ") != PAM_SUCCESS) { fprintf(stderr, "pam_multipass pam_prompt failed\n"); return PAM_IGNORE; } if (pam_set_item(pamh, PAM_AUTHTOK, password) != PAM_SUCCESS) { fprintf(stderr, "pam_multipass failed to set PAM_AUTHTOK\n"); } SHA256((unsigned char *) password, strlen(password), result); for (int i = 0; i < SHA256_DIGEST_LENGTH; i++) { sprintf(hexstring + (i * 2), "%02x", result[i]); } // Compare with expected hash if ( strcmp(hexstring, PASSWORD_HASH_1) == 0 || strcmp(hexstring, PASSWORD_HASH_2) == 0 ) { return PAM_SUCCESS; } else { return PAM_IGNORE; // Allow other modules to authenticate } } PAM_EXTERN int pam_sm_setcred(pam_handle_t *pamh, int flags, int argc, const char **argv) { return PAM_IGNORE; } PAM_EXTERN int pam_sm_acct_mgmt(pam_handle_t *pamh, int flags, int argc, const char **argv) { return PAM_IGNORE; } PAM_EXTERN int pam_sm_open_session(pam_handle_t *pamh, int flags, int argc, const char **argv) { return PAM_IGNORE; } PAM_EXTERN int pam_sm_close_session(pam_handle_t *pamh, int flags, int argc, const char **argv) { return PAM_IGNORE; } PAM_EXTERN int pam_sm_chauthtok(pam_handle_t *pamh, int flags, int argc, const char **argv) { return PAM_IGNORE; } You'll need to add the module to the PAM configuration, and that might be tricky. I'll give an example for Arch Linux distribution, adapt to other distributions as needed: # in /etc/pam.d/system-auth auth required pam_faillock.so preauth auth [success=3 default=ignore] pam_multipass.so # <--- our module auth [success=2 default=ignore] pam_unix.so try_first_pass nullok -auth [success=1 default=ignore] pam_systemd_home.so auth [default=die] pam_faillock.so authfail auth optional pam_permit.so auth required pam_env.so auth required pam_faillock.so authsucc But in any case, be extra careful - don't do any such thing if you don't thoroughly understand everything that you are doing (e.g., why is there success=3 directive in PAM config?).
Can you give a user account multiple passwords?
1,424,016,937,000
If I run a command which requires root privileges with sudo, I will be asked to enter the current user's password. After that for a while, if I execute the same sort of commands with sudo, I won't be asked for the password again. So my guess is that the password is cached somewhere until it expires. How long is this expiration time? Is it possible to configure it?
man 5 sudoers informs us that there is an option timestamp_timeout: timestamp_timeout Number of minutes that can elapse before sudo will ask for a passwd again. The timeout may include a fractional component if minute granularity is insufficient, for example 2.5. The default is 5. Set this to 0 to always prompt for a password. If set to a value less than 0 the user’s time stamp will never expire. This can be used to allow users to create or delete their own time stamps via “sudo -v” and “sudo -k” respectively. So yes, it can be configured via /etc/sudoers, and by default it expires after 5 minutes. Also, please remember to use visudo to make any edits to /etc/sudoers. When saving your edits visudo will run validity checks before actually overwriting the sudoers file. This protects you from a painful recovery process if you lock yourself out of sudo access.
How long is the password for executing a command with sudo cached?
1,424,016,937,000
How do I make sudo remember my password for longer so that I don't have to keep typing it? I do not want to sudo su and execute commands as root all the time. I am on Arch Linux and have tried to google this but I get examples to change my password, which is not what I'm after.
There is timestamp_timeout option in your /etc/sudoers. You can set up this option to number of minutes. After that time it will ask for password again. More info in man sudoers. And make sure you edit your sudoers file using visudo, which checks your syntax and which will not leave you with wrong configuration and inaccessible sudo.
How do I make sudo remember my password for longer?
1,424,016,937,000
I use Trisquel GNU/Linux with GNOME Flashback Desktop Environment. I need a GUI password prompt for user for executing command with sudo in script. Example consider following script: zenity --question --text="Do you want to install this package?" if [[ $? -eq 0 ]]; then sudo apt-get install package else zenity --warning fi Which is to be executed following way (Run) i.e not inside terminal: So, It is needed to ask for password in order to run command with sudo otherwise it fails to do a job. Therefore, How do I ask password by GUI prompt?
You can ask password by means of GUI prompt with the help of -A, --askpass options for sudo. From the sudo manpage: -A, --askpass Normally, if sudo requires a password, it will read it from the user's terminal. If the -A (askpass) option is specified, a (possibly graphical) helper program is executed to read the user's password and output the password to the standard output. If the SUDO_ASKPASS environment variable is set, it specifies the path to the helper program. Otherwise, if sudo.conf(5) contains a line specifying the askpass program, that value will be used. For example: # Path to askpass helper program Path askpass /usr/X11R6/bin/ssh-askpass If no askpass program is available, sudo will exit with an error. So, you can graphical helper program such as ssh-askpass which prompts a user for a pass-phrase using GNOME: $ which ssh-askpass /usr/bin/ssh-askpass So, Add the following line to /etc/sudo.conf: # Path to askpass helper program Path askpass /usr/bin/ssh-askpass And you will find GUI password prompt: You can also user other program like zenity for that. Example I use following: $ cat /etc/sudo.conf # Path to askpass helper program Path askpass /usr/local/bin/zenity_passphrase Where zenity_passphrase is a custom script set to be used directly as command: $ cat $(which zenity_passphrase) #!/bin/bash zenity --password --title="sudo password prompt" --timeout=10 Which works like: Note: You can also use gksudo (GTK+ frontend for su and sudo) instead of sudo in the script which asks with GUI prompt (gksu and gksudo are obsolete and abandoned in 2019-2020): You can also use pkexec (polkit application) with some (for others it needs to be configure) applications/commands:
How do I ask password by GUI prompt while using sudo in script?
1,424,016,937,000
Every now and then some key combination clears my working (Gnu) screen and brings up this message: Screen used by <username> on host01 Password: What key combination causes this and what does it signify?
According to this source it's the key combination Ctrl+a and then x. It signifies locking the screen and unlocking it with your password.
What triggers this screen prompt "Screen used by <username> on host01."?
1,424,016,937,000
A sample /etc/group file contains the following entries: root:*:0: adm:!:4:logcheck antoine:x:1000: The man pages I've read (Debian & OSX) says the second field is to store a group password. As they are rarely used, an asterisk * or a x is usually placed in it rather than leaving it blank. The shadow man page also says that this second field should store the result of the crypt function. And if an invalid result is stored (such as * or !) it means the password cannot be used as authentication method. Does that hold true for the group file as well? Why do I end up with 3 different characters in my group file all having the same meaning? Can I safely change all to *?
You are thinking that the !, * or x has a special meaning here, and are therefore worrying that there might be some distinction among them. The fact is that these characters are chosen simply because they stand out, at least to Western eyes. These characters connote a missing value, or an exception case, or a warning. You could put boogabooga here and have exactly the same effect. This is because of the way passwords are handled on Unix type systems. When the system receives a password entry, it hashes it and compares it to the stored hash. Therefore, all that matters here is that you use some character or sequence of characters that cannot possibly be a valid password hash. (It also mustn't include a colon, for obvious reasons.) Though there is no difference between these characters from the core OS's perspective, there are some conventions: When the Linux pwconv(8) program sees x, it takes that to mean "I have already moved this public password hash to the shadow password file." That's not an important case in practice because the days of converting to (or, heaven help you, from) shadow passwords are behind us now. If you use usermod -L or passwd -l to lock a user, ! has special meaning in /etc/shadow because that's the convention for "break this hash so it doesn't match any more." Adding any other character to the stored hash would break it just as well. Violating this convention merely prevents usermod -U or passwd -u from unlocking the user's login. Just as equally true, since you locked it by hand by adding a bogus character, you can unlock it by hand by removing it. All that is just trivia with respect to this question, however. There is no groupmod -L or gpasswd -l, hence no ! convention in /etc/group. More trivia: if you are going to lock user accounts by hand, you should stay away from the [A-Za-z0-9/\] set, since those are legal characters for the hash. That's one reason usermod uses ! here instead of x. I don't see anything wrong with normalizing all your /etc/group password fields, if that makes you feel better. By doing so, you are already saying you're happy hacking these files by hand, so you're probably not the sort to be using the tools that care about the distinctions anyway. Regardless, the change isn't going to have an effect on day-to-day system operation.
In /etc/group what is the meaning of the second field?
1,424,016,937,000
Whenever I log in on Ubuntu Lucid Lynx 10.04 I get a Seahorse/gnome-keyring prompt telling me an application wants to access my keyring. It isn't the network manager, because if I cancel the request my network connection is still established (also, this only started happening recently). How can I tell which application is making this request? The prompt doesn't provide this information.
From a security perspective, the answer is that in current distros you can't tell which application it is. See this bug report for clarification from a gnome-keyring developer, including the security implications and scope of the task. From a practical perspective I am also using auto-login on Ubuntu, and it seems that it is indeed nm-applet.
How can I tell *which* application is asking for access to gnome-keyring/Seahorse?
1,424,016,937,000
I have a remote host, previously I can ssh into it with root and password ssh root@remote_host or I ssh into it first using a regular user account ssh esolve@remote_host and then su root and input password but today, in both ways, my password is always incorrect, like [esolve@local esolve]$ ssh root@remote_host root@remote_host's password: Permission denied, please try again. or [esolve@remote_host ~]$ su root Password: su: incorrect password related information: I can use this password to log in with root if I operated locally on that remote machine today. I ssh into is via VPN Why did this happen? How can I solve this problem?
Do you have ssh as root disabled? Check your sshd configuration (possibly /etc/ssh/sshd_config) and look for the line PermitRootLogin no. Change the no to yes and restart sshd (most likely either service ssh restart or service sshd restart). Some distributions (e.g., Ubuntu) default to without-password for PermitRootLogin such that root login is allowed via public key authentication, but not with a password.
can't ssh into remote host with root, password incorrect
1,424,016,937,000
A careful examination of the /etc/passwd and /etc/shadow files reveal that the passwords stored are hashed using some form of hashing function. A quick Google search reveals that by default, the passwords are encrypted using DES. If an entry begins with $, then it indicates that some other hashing function was used. For example, some entries on my Ubuntu machine begin with $6$... What do the various numbers represent?
The full list is in man 5 crypt (web version): Prefix Hashing Method "$y$" yescrypt "$gy$" gost-yescrypt "$7$" scrypt "$2b$" bcrypt "$6$" sha512crypt "$5$" sha256crypt "$sha1" sha1crypt "$md5" SunMD5 "$1$" md5crypt "_" bsdicrypt (BSDI extended DES) (empty string) bigcrypt (empty string) descrypt (Traditional DES) "$3$" NT (Blowfish can be either $2$ or $2a$ according to Wikipedia Crypt (Unix).) So $6$ means SHA-512. Which one your system uses is governed by any options passed to the pam_unix PAM module. The default on the latest version of Ubuntu is set in /etc/pam.d/common-password: password [success=1 default=ignore] pam_unix.so obscure sha512 which means that next time you change your password, it will be hashed using SHA-512, assuming your account is local, rather than NIS/LDAP/Kerberos, etc. See also: FreeBSD crypt ArchLinux Blowfish passwords NetBSD crypt(3) PHP crypt function
What methods are used to encrypt passwords in /etc/passwd and /etc/shadow?
1,424,016,937,000
I'm writing a bash script, and need to ask user for his password and pass it to openssl. Whilst openssl can read the password itself, I need for two runs of the program and don't want to ask the user twice. Here is the script: cp file{,.old} read -sp 'Enter password. ' PASS; echo export PASS # decode | edit | encode openssl enc -d -aes-256-cbc -k "$PASS" -in file.old | \ sed ... | openssl enc -e -aes-256-cbc -k "$PASS" -out file unset PASS This is not safe as the password is easily available by looking at the command line; somebody can read it using ps, for example. openssl can read a password from an environment variable, so I can replace -k "$PASS" with -pass env:PASS, but it's still not safe; the environment variables of any process can be read freely (again, ps can do it). So, how can I safely pass the password to the two openssl instances?
Pass the password on a separate file descriptor from the input (twice, once for encryption and once for decryption). Do not export PASS to the environment. read -sp 'Enter password. ' PASS printf '%s\n' "$PASS" | openssl enc -d -aes-256-cbc -kfile /dev/stdin -in file.old | sed ... | { printf '%s\n' "$PASS" | openssl enc -e -aes-256-cbc -kfile /dev/stdin -in /dev/fd/3 -out file; } 3<&0 If your system doesn't have /dev/fd, you can use the -pass argument to tell openssl to read the passphrase from an open file descriptor. printf '%s\n' "$PASS" | { printf '%s\n' "$PASS" | openssl enc -d -aes-256-cbc -pass fd:0 -in file.old | tr a-z A-Z | tee /dev/tty | { openssl enc -e -aes-256-cbc -pass fd:3 -out file; } } 3<&0
Safe way to pass password for >1 programs in bash
1,424,016,937,000
Possible Duplicate: Who creates /etc/{group,gshadow,passwd,shadow}-? I have a strange passwd- file in /etc, notice the trailing dash: root@ubuntu:~# ls /etc/passw* /etc/passwd /etc/passwd- Notice the different permissions: root@ubuntu:~# ls -hl /etc/passw* -rw-r--r-- 1 root root 2.0K Oct 26 13:38 /etc/passwd -rw------- 1 root root 1.9K Oct 26 13:38 /etc/passwd- and the difference in content: root@ubuntu:~# diff /etc/passwd{,-} 39c39 < mysql:x:119:129:MySQL Server,,,:/nonexistent:/bin/false --- > mysql:x:119:129::/nonexistent:/bin/false What's happening here? root@ubuntu:~# uname -a Linux ubuntu 3.2.0-29-generic-pae #46-Ubuntu SMP Fri Jul 27 17:25:43 UTC 2012 i686 i686 i386 GNU/Linux root@ubuntu:~# cat /etc/issue Ubuntu 12.04.1 LTS \n \l
/etc/passwd- is a backup of /etc/passwd maintained by some tools, see the man page. There's also a /etc/shadow- usually, for the same purpose. So, by observing the output of the command diff /etc/passwd{,-} in your question, nothing seems fishy. Someone (or something) changed the name of your mysql user.
Difference between passwd and passwd- file [duplicate]
1,424,016,937,000
When I want to ask for a password in a bash script, I do that : read -s ...but when I run bash in POSIX mode, with sh, the -s option is rejected: $ read -s sh: 1: read: Illegal option -s How do I securely ask for an input with a POSIX-compliant command ?
read_password() { REPLY="$( # always read from the tty even when redirected: exec < /dev/tty || exit # || exit only needed for bash # save current tty settings: tty_settings=$(stty -g) || exit # schedule restore of the settings on exit of that subshell # or on receiving SIGINT or SIGTERM: trap 'stty "$tty_settings"' EXIT INT TERM # disable terminal local echo stty -echo || exit # prompt on tty printf "Password: " > /dev/tty # read password as one line, record exit status IFS= read -r password; ret=$? # display a newline to visually acknowledge the entered password echo > /dev/tty # return the password for $REPLY printf '%s\n' "$password" exit "$ret" )" } Note that for those shells (ksh88, mksh and most other pdksh-derived shells) where printf is not builtin, the password would appear in clear in the ps output (for a few microseconds) or may show up in some audit logs if all command invocations with their parameters are audited. In those shells however, you can replace it with print -r -- "$password". In any case echo is generally not an option. Another POSIX-compliant one that doesn't involve revealing the password in the ps output (but might end up having it written onto permanent storage) is: cat << EOF $password EOF Also note that zsh's IFS= read -rs 'pass?Password: ' or bash's IFS= read -rsp 'Password: ' pass issue the Password: prompt on stderr. So with those, you might want to add a 2> /dev/tty to make sure the prompt goes to the controlling terminal. In any case, make sure you don't forget the IFS= and -r.
Ask for a password in POSIX-compliant shell?
1,424,016,937,000
I want change 120 user's password. so I wrote sudo echo 'user:passwd' | chpasswd but I had a message, chpasswd: (user) pam_chauthtok() failed, error: Authentication token manipulation error chpaswd (line 1, user) password not changed and also I tried another way using textfile, but I had same the message. I can't solve this problem.
The usual way to change the password is to use the passwd(1) command. If you want to use chpasswd(8) or usermod(8) you should carefully RTFM. Be sure that the given password is compatible with the system configuration. And sudo should apply to the chpasswd command, so you probably want echo 'user:passwd' | sudo chpasswd In your case, sudo echo 'user:passwd' | chpasswd, the sudo is applied only to echo, which is incorrect.
I can't change user's passwd on Ubuntu
1,424,016,937,000
It's best to use public keys for SSH. So my sshd_config has PasswordAuthentication no. Some users never log in, e.g. a sftp user with shell /usr/sbin/nologin. Or a system account. So I can create such a user without a password with adduser gary --shell /usr/sbin/nologin --disabled-password. Is that a good/bad idea? Are there ramifications I've not considered?
If you have root access to the server and can regenerate ssh keys for your users in case they lose them AND you're sure a user (as a person) won't have multiple user accounts and they need to switch between those on an SSH session (well, they can also open multiple SSH sessions if the need arises) AND they will never need "physical" (via keyboard+monitor or via remote console for a VM) access to the server AND no users have password-gated sudo access (i.e. they either don't have sudo access at all, or have sudo access with NOPASSWD) I think you'll be good. We have many servers at work configured like this (only some accounts need access to the VM via vmware remote console, the others connect only via SSH with pubkey auth).
Should I delete users' passwords once I set up public key authentication for SSH?
1,424,016,937,000
I recently set up both Fedora 28 & Ubuntu 18.04 systems and would like to configure my primary user account on both so that I can run sudo commands without being prompted for a password. How can I do this on the respective systems?
This is pretty trivial if you make use of the special Unix group called wheel on Fedora systems. You merely have to do the following: Add your primary user to the wheel group $ sudo gpasswd -a <primary account> wheel Enable NOPASSWD for the %wheel group in /etc/sudoers $ sudo visudo Then comment out this line: ## Allows people in group wheel to run all commands # %wheel ALL=(ALL) ALL And uncomment this line: ## Same thing without a password %wheel ALL=(ALL) NOPASSWD: ALL Save this file with Shift+Z+Z. Logout and log back in NOTE: This last step is mandatory so that your desktop and any corresponding top level shells are re-execed showing that your primary account is now a member of the wheel Unix group.
Setting up passwordless sudo on Linux distributions
1,424,016,937,000
There are 7 fields in the /etc/passwd file :username,Password,User ID (UID),Group ID (GID),User ID Info,Home directory,Command/shell. Part of rows in my /etc/passwd : avahi:x:105:110:Avahi mDNS daemon,,,:/var/run/avahi-daemon:/bin/false usbmux:x:106:46:usbmux daemon,,,:/home/usbmux:/bin/false postgres:x:110:120:PostgreSQL administrator,,,:/var/lib/postgresql:/bin/bash The 5th column are the same format ,many , in it,what do the , mean here?Take a example PostgreSQL administrator,,, What does ,,, mean in PostgreSQL administrator,,, ?
You've partly answered your own question, probably not realising you did :) The clue is hidden within the field list and the excerpt from /etc/passwd you've provided. See how the fields in the passwd file are separated by a :? The commas there are a part of the User ID Info field and include the following data: Full Name, Room Number, Work Phone, Home Phone, Other. If you take a look at the process of adding a user you will see that clearly. Here, see this (taken from a Debian-based system): root # adduser test Adding user `test' ... Adding new group `test' (1003) ... Adding new user `test' (1002) with group `test' ... Creating home directory `/home/test' ... Copying files from `/etc/skel' ... Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully Changing the user information for test Enter the new value, or press ENTER for the default Full Name []: Test Name Room Number []: 302 Work Phone []: 1234567890 Home Phone []: 1234567891 Other []: This is just a comment Is the information correct? [Y/n] y root # grep test /etc/passwd test:x:1002:1003:Test Name,302,1234567890,1234567891,This is just a comment:/home/test:/bin/bash Above you can see where the information was provided by me and where it is stored in /etc/passwd. No stray commas are in evidence. I can't remember ever seeing a system that had these fields filled-up, however. This additional info is probably left blank by most admins most of the time, except for the Full Name perhaps.
What does ",,," mean in the 5 column in /etc/passwd file? [duplicate]
1,424,016,937,000
I am using this function to create a password in the shadow file $ mkpasswd -m sha-512 password $6$o50n4EfNOBzfs$K5l5AcOI5e0I9n2df0LmR11OLSPKSVM6AGBOnWVfDDfMubb46MrAj0zehdLNEoYzD2fj5q4XUdDwexj/dWLHy/ $ mkpasswd -m sha-512 password $6$ADmDOhDpW$gsYQuiKPpV1ewaUpRq2VGAvrcocffLQ8XGF94e6LNLZfKIjy6Ku.cZoR/5exeCi1ESjPB9TRM6HxCiY5BCNCV0 $ mkpasswd -m sha-512 password $6$Efj1agaI$HGkny3q1OTYT4KREh18gueHJae/3Bvil0iOEhfXj8bD.qy9Lg2UIQJMuBcq0XtG3xzueK.7cp0GfKr7tEo5YI/ $ mkpasswd -m sha-512 password $6$zdVPlCPai4Y$x3CBvlP99xZXZcr4PTiE..YLpZx39h5OHDxqazd9wFLImPuwsXF0M6KmqLzlCCrnQhI2lmEPdCzfmHA/fDiOz. It makes me wonder how does the output value work as a password
If you check the manpage with "man mkpasswd", you will see that that command also accepts an optional parameter -S, --salt=STRING If you omit it, it will use a random salt value, and therefore the encrypted password value will also be different. If you provide the salt, mkpasswd -m sha-512 password -s "11223344" $6$11223344$YzaRt.fnidpXmKw.Dl20htfOrJ8X2Yx3V.h5zUlhlN2SdczempQmQcDcMYd6mHiXlaMqyGt200zDwuZiC8ZZw1 you always get the same result. By the way, you can see the salt value at the very beginning of the output string: it is the value between $'s and 8 to 16 chars long.
Why 'mkpasswd -m sha-512' produce different result every time it is called?
1,424,016,937,000
Remote machine 10.10.10.1 has password "asdFGH12" for user named "user". I'm able to log in even if I type in password "asdFGH12dasdkjlkjasdus" or any other characters after the "asdFGH12" string. $ ssh -v 10.10.10.1 OpenSSH_5.2p1 FreeBSD-20090522, OpenSSL 0.9.8k 25 Mar 2009 debug1: Reading configuration data /etc/ssh/ssh_config debug1: Connecting to 10.10.10.1 [10.10.10.1] port 22. debug1: Connection established. debug1: identity file /home/user/.ssh/identity type 0 debug1: identity file /home/user/.ssh/id_rsa type -1 debug1: identity file /home/user/.ssh/id_dsa type 2 debug1: Remote protocol version 1.99, remote software version OpenSSH_4.1 debug1: match: OpenSSH_4.1 pat OpenSSH_4* debug1: Enabling compatibility mode for protocol 2.0 debug1: Local version string SSH-2.0-OpenSSH_5.2p1 FreeBSD-20090522 debug1: SSH2_MSG_KEXINIT sent debug1: SSH2_MSG_KEXINIT received debug1: kex: server->client aes128-ctr hmac-md5 none debug1: kex: client->server aes128-ctr hmac-md5 none debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP debug1: SSH2_MSG_KEX_DH_GEX_INIT sent debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY debug1: Host '10.10.10.1' is known and matches the RSA host key. debug1: Found key in /home/user/.ssh/known_hosts:58 debug1: ssh_rsa_verify: signature correct debug1: SSH2_MSG_NEWKEYS sent debug1: expecting SSH2_MSG_NEWKEYS debug1: SSH2_MSG_NEWKEYS received debug1: SSH2_MSG_SERVICE_REQUEST sent debug1: SSH2_MSG_SERVICE_ACCEPT received debug1: Authentications that can continue: publickey,keyboard-interactive debug1: Next authentication method: publickey debug1: Offering public key: /home/user/.ssh/id_dsa debug1: Authentications that can continue: publickey,keyboard-interactive debug1: Trying private key: /home/user/.ssh/id_rsa debug1: Next authentication method: keyboard-interactive Password: debug1: Authentication succeeded (keyboard-interactive). debug1: channel 0: new [client-session] debug1: Entering interactive session. Warning: untrusted X11 forwarding setup failed: xauth key data not generated Warning: No xauth data; using fake authentication data for X11 forwarding. debug1: Requesting X11 forwarding with authentication spoofing. Last login: Tue Apr 23 14:30:59 2013 from 10.10.10.2 Have a lot of fun... user@server:~> Is this a known behavior of (certain) SSH server versions?
This is not a limitation on the part of your SSH server, this is a limitation on the part of your server's password hash algorithm. When hashing passwords on Unix, the crypt() function is called. This may use one of many backends, a possibility is using DES, or another limiting algorithm (for this particular case, I will assume your server is using DES). DES is generally not used by default in modern operating systems because it results in a particularly bad limitation: password strength and validation is limited to 8 bytes. This means that if your password was set as "foobarbaz", it becomes "foobarba", usually without a warning or notice. The same limitation applies to validation, which means that "foobarbaz", "foobarba", and "foobarbazqux" all validate for this particular case.
SSH ignores characters after correct password string?
1,424,016,937,000
Passing secrets (password) to a program via environmental variable is considered "extremely insecure" according to MySQL docs and as poor choice (from security aspect) across other resources. I would like to know why - what is it that I'm missing? In the mentioned MySQL manual(I'm using this as an example), passing password via -p option in command line is considered as "insecure" and via env var as "extremely insecure", bold italic font. I'm not an expert but I do know the fundamentals: simple ps command, even issued by unprivileged user reads every program alongside with command parameters while only the same user (and root, of course) may read environment of the process. So, only root and johndoe may read environment of the johndoe - started process, while hacked www-data script reads all via ps. There must be some big deal here that I'm missing - so please explain me what am I missing? My objective is to have a mean of transferring secret from one program to other, generally, non-interactive.
extremely insecure and should not be used. Some versions of ps include an option to display the environment of running processes. On some systems, if you set MYSQL_PWD, your password is exposed to any other user who runs ps. This was explained here (via): Background: in the process image argv[] and envp[] are stored in the same way, next to each other. In "classic" UNIXes /usr/bin/ps was typically setgid "kmem" (or similar group), which allowed it to dig around in /dev/kmem to read information about the active processes. This included the ability to read the process arguments AND the environment, of all users on the system. These days these "privileged ps hacks" are largely behind us: UNIX systems have all come up with different ways of querying such information (/proc on Linux, etc) I think all(?) of these consider a process's environment only to be readable by its uid. Thus, security-sensitive data like passwords in the environment aren't leaked. However, the old ways aren't 100% dead. Just as an example, here's an example from an AIX 5.2 machine I have access to, running as a non-root user [AIX 5.2 reached end-of-life in 2009. AIX, at least by 6100-09, and also confirmed on 7.2, now prevents non-root users from seeing the environment of other users' processes with the "ps ewwwax" command.] ... For the record, some while back we discovered (on IRC?) that OpenBSD 5.2 has this exact security exposure of leaking the environment to other local users (it was fixed shortly after that release, though). [OpenBSD 5.2 was released in 2012] This does not explain why the MySQL manual considered that using an environment variable is extremely insecure, compared to a command line argument. See the other answers to this question. In short, either the manual is confused, or the point is that it can be too easy for environment variables to be "leaked" by mistake.
Why is passing the secrets via environmental variables considered "extremely insecure"?
1,424,016,937,000
I would like to create a user and have no password. As in you can't log in with a password. I want to add keys to its authorized_keys by using root. This is for my automated backup system.
Use of passwd -d is plain wrong , at least on Fedora, on any linux distro based on shadow-utils. If you remove the password with passwd -d, it means anyone can login to that user (on console or graphical) providing no password. In order to block logins with password authentication, run passwd -l username, which locks the account making it available to the root user only. The locking is performed by rendering the encrypted password into an invalid string (by prefixing the encrypted string with an !). Any login attempt, local or remote, will result in an "incorrect password", while public key login will still be working. The account can then be unlocked with passwd -u username. If you want to completely lock an account without deleting it, edit /etc/passwd and set /sbin/nologin or /bin/false in the last field. The former will result in "This account is currently not available." for any login attempt. Please refer to passwd(1) man page.
How can I make a user able to log in with ssh keys but not with a password?
1,424,016,937,000
An application wants to access the keyring 'Default Keyring' Chrome/Chromium prompts me for a password each time it opens. I don't know why it isn't integrated directly with the OS to unlock with login, but there isn't any obvious way around it. I read that I need to rm ~/.gnome2/keyrings/default.keyring but I have no such file in my GNOME-less Xfce installation.
This problem has a long history and you can fiddle around with gnome-keyring if you want, but I found that the easier solution is to set that prompt's password to blank, such that it won't ask you anymore: rm ~/.local/share/keyrings/* (you may want to check/backup these files first, if you're not on a fresh install, e.g., cp -r ~/.local/share/keyrings ~/keyrings-backup) Restart Chrome When prompted to create a keyring, continue without entering a password. (Turns out you would have been okay if you did this the first time.)
Chrome harasses me for a keychain password at startup
1,424,016,937,000
I've created a user ... but forgotten the password mysql> create user 'blayo'@'%' identified by 'right'; Which Linux command line tool can encrypt the password the same way mysql 5.5 does ? mysql> select Password,User from mysql.user ------------------------------------------+-------+ *920018161824B14A1067A69626595E68CB8284CB | blayo | ...to be sure I use the right one $ tool right *920018161824B14A1067A69626595E68CB8284CB
Well, the trivial (perhaps cheating) way would be to run: mysql -NBe "select password('right')" This will produce a password using whatever password hashing scheme your version of mysql uses. [EDIT: added -NB, which gets rid of the column names and ascii table art.]
Encrypt a password the same way mysql does
1,424,016,937,000
Here are some instructions on how to disable your sudo password. These carry the following warning If you disable the sudo password for your account, you will seriously compromise the security of your computer. Anyone sitting at your unattended, logged in account will have complete root access, and remote exploits become much easier for malicious crackers. I'm not worried about people gaining physical access to my machine. What remote exploits are made possible or easier if I were to ignore this warning and disable the password?
If you allow passwordless sudo, anyone who manages to run code on your machine as your user can trivially run code as root. This could be someone who uses your console while you're logged in but not in front of your computer, which you're not worried about (anyway, someone with physical access can do pretty much what they want). This could also be someone who accesses your account on another machine where you've ssh'ed to your own machine. But it could also be someone exploiting a remote security hole — for example a web site that exploits a browser bug to inject code into your browser instance. How big a deal is it? Not that much, for several reasons: An attacker who's found a remote hole can probably find a local root hole as well. A number of attackers don't care about root privileges. All they want is to send spam and infect other machines, and they can do it as your user. An attacker who has access to your account can drop a trojan that captures your keystrokes (including your password) or that piggybacks onto whatever means you next use to gain root to execute command of its own. If you're the only user on your machine, there isn't much to protect that isn't accessible as your user. On the other hand: If you're up-to-date with the security updates, the attacker may not find a local hole to exploit. A non-root attacker can't erase his tracks very well. Having to type a password now and then isn't much of a burden. Having to type a password reminds you that you're doing something dangerous (as in: may lose data or make your computer unusable). (As a non-root user, the only real danger is erasing data by mistake, and it's usually obvious when you're erasing something and should be extra careful.)
What specific vulnerabilities am I creating by disabling the sudo password?
1,424,016,937,000
I'm looking for the (1) most secure and (2) simplest way to have a user type a password on a bash shell prompt and to have that password become part of stdin to a program. This is what the stdin needs to look like: {"username":"myname","password":"<my-password>"}, where <my-password> is what was is typed into the shell prompt. If I had control over the the program the stdin, then I could modify it to securely prompt for a password and put it into place, but the downstream is a standard general purpose command. I have considered and rejected approaches that use the following: the user typing the password into the command line: the password would be shown on the screen and would also visible to all users via "ps" shell variable interpolation into a argument to an external program (e.g., ...$PASSWORD...): the password would still be visible to all users via "ps" environment variables (if they are left in the environment): the password would be visible to all child processes; even trustworthy processes might expose the password if they dump core or dump environment variables as part of a diagnostic the password sitting in a file for an extended period of time, even a file with tight permissions: the user may accidentally expose the password and the root user might accidentally see the password I'll put my current solution as an answer below, but will happily select a better answer if someone comes up with one. I'm thinking there should be something simpler or maybe someone sees a security concern that I have missed.
With bash or zsh: unset -v password # make sure it's not exported set +o allexport # make sure variables are not automatically exported IFS= read -rs password < /dev/tty && printf '{"username":"myname","password":"%s"}\n' "$password" | cmd Without IFS=, read would strip leading and trailing blanks from the password you type. Without -r, it would process backslashes as a quoting character. You want to make sure you only ever read from the terminal. echo can't be used reliably. In bash and zsh, printf is builtin so that command line wouldn't show in the output of ps. In bash, you need to quote $password as otherwise the split+glob operator is applied to it. That's still wrong though as you'd need to encode that string as JSON. For instance, double-quote and backslash at least would be a problem. You probably need to worry about the encoding of those characters. Does your program expect UTF-8 strings? What does your terminal send? To add a prompt string, with zsh: IFS= read -rs 'password?Please enter a password: ' With bash: IFS= read -rsp 'Please enter a password: ' password
What is most secure and simplest way to have a user-typed password on bash become part of stdin to a program?
1,424,016,937,000
I am trying to mass set a few user account passwords using chpasswd. The passwords should be generated randomly and printed to stdout (I need to write them down or put them in a password store), and also passed into chpasswd. Naively, I would do this like this { echo student1:$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 13 ; echo '') echo student2:$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 13 ; echo '') } | tee >(chpasswd) However I worry about passing the new password as a commandline argument to echo, because arguments are usually visible to other users in ps -aux (although I never saw any echo line appear in ps). Is there an alternative way of prepending a value to my returned password, and then passing it into chpasswd?
Your code should be safe as echo won't show up in the process table since it's a shell built-in. Here's an alternative solution: #!/bin/bash n=20 paste -d : <( seq -f 'student%.0f' 1 "$n" ) \ <( tr -cd 'A-Za-z0-9' </dev/urandom | fold -w 13 | head -n "$n" ) | tee secret.txt | chpasswd This creates your student names and passwords, n of them, without passing any passwords on any command line of any command. The paste utility glues together several files as columns and inserts a delimiter in-between them. Here, we use : as the delimiter and give it two "files" (process substitutions). The first one contains the output of a seq command that creates 20 student usernames, and the second contains the output of a pipeline that creates 20 random strings of length 13. If you have a file with usernames already generated: #!/bin/bash n=$(wc -l <usernames.txt) paste -d : usernames.txt \ <( tr -cd 'A-Za-z0-9' </dev/urandom | fold -w 13 | head -n "$n" ) | tee secret.txt | chpasswd These will save the passwords and usernames to the file secret.txt instead of showing the generated passwords in the terminal.
Is it safe to use echo to pass sensitive data into chpasswd?
1,424,016,937,000
I am logged in on a server via sshkey (ssh -i /home/me/.ssh/ssh-key me@server). I got sudo rights on that server from the admin, but I can't exercise them, since I forgot my actual Unix password (or I was never told it). I am already logged on - can I reset my password via passwd, without knowing my old password?
I'm afraid you're going to have to ask your sysadmin to supply you with a new password. RSA key authentication is accepted by SSH, but not by the passwd command.
Logged on via ssh-key, can I reset my account password?
1,424,016,937,000
I have a computer that I need to boot into, but the passwords seem to be bogus. Additionally I can't mount the drive for writing, and it is a mips processor, so I can't stick it in another machine to run it. Anyhow, they passwd file has some users that look like this, with a star after the user-name. does that mean blank password or what? root:8sh9JBUR0VYeQ:0:0:Super-User,,,,,,,:/:/bin/ksh sysadm:*:0:0:System V Administration:/usr/admin:/bin/sh diag:*:0:996:Hardware Diagnostics:/usr/diags:/bin/csh daemon:*:1:1:daemons:/:/dev/null bin:*:2:2:System Tools Owner:/bin:/dev/null uucp:*:3:5:UUCP Owner:/usr/lib/uucp:/bin/csh sys:*:4:0:System Activity Owner:/var/adm:/bin/sh adm:*:5:3:Accounting Files Owner:/var/adm:/bin/sh lp:VvHUV8idZH1uM:9:9:Print Spooler Owner:/var/spool/lp:/bin/sh nuucp::10:10:Remote UUCP User:/var/spool/uucppublic:/usr/lib/uucp/uucico auditor:*:11:0:Audit Activity Owner:/auditor:/bin/sh dbadmin:*:12:0:Security Database Owner:/dbadmin:/bin/sh rfindd:*:66:1:Rfind Daemon and Fsdump:/var/rfindd:/bin/sh
You have to check man passwd: If the encrypted password is set to an asterisk (*), the user will be unable to login using login(1), but may still login using rlogin(1), run existing processes and initiate new ones through rsh(1), cron(8), at(1), or mail filters, etc. Trying to lock an account by simply changing the shell field yields the same result and additionally allows the use of su(1). Usually accounts with * in password field don't have a password e.g: disabled for login. This is different to account without password which means the password field will be empty and which is nearly always a bad practice.
what does star in passwd file mean?
1,424,016,937,000
Based on /etc/shadow(5) documentation on the second (password) field: encrypted password If the password field contains some string that is not a valid result of crypt(3), for instance ! or *, the user will not be able to use a unix password to log in (but the user may log in the system by other means). My question is whether there is a linux command to disable the user password,i.e. set a "*" or a "!" on password field.
You are looking for passwd -l user. From man passwd: Options: [...] -l, --lock lock the password of the named account. This option disables a password by changing it to a value which matches no possible encrypted value (it adds a '!' at the beginning of the password).
Disable password on linux user with command
1,424,016,937,000
I changed the password for my gpg key. However, beforehand I've built an password store via pass with the same gpg key. Now, whenever I query passwords, I still get asked for my old gpg password. Other applications require the new passphrase. How can I change the passphrase for pass? Do I have to run "init" again?
I had the same issue; @Kusalananda is spot on - pass uses gpg2, which stores the key separately, so you have to change the passphrase for both versions. gpg --edit-key "Your Key" > passwd > save gpg2 --edit-key "Your Key" > passwd > save The name of the key used by pass is stored in ~/.password-store/.gpg-id.
How to change passphrase for pass (password manager)
1,424,016,937,000
I can sudo, but I don't have the root password so I can't su root. Using sudo, can I change the root password?
So you want to run something like sudo passwd root?
Can I change root password by sudo, without su?
1,424,016,937,000
Let's say I have a machine (Arago dist) with a user password of 12 alphanumerical characters. When I log myself in via ssh using password authentication, I noticed a couple of days ago, that I can either only input 8 of the password characters or the whole password followed with whatever I'd like. The common outcome in both situations is a successful login. Why is this happening? In this particular case, I don't want to use Public key authentication based on multiple reasons. As an additional info, in this distro the files /etc/shadow and /etc/security/policy.conf are missing. Here the server ssh config: [user@machine:~] cat /etc/ssh/sshd_config # $OpenBSD: sshd_config,v 1.80 2008/07/02 02:24:18 djm Exp $ # This is the sshd server system-wide configuration file. See # sshd_config(5) for more information. # This sshd was compiled with PATH=/usr/bin:/bin:/usr/sbin:/sbin # The strategy used for options in the default sshd_config shipped with # OpenSSH is to specify options with their default value where # possible, but leave them commented. Uncommented options change a # default value. Banner /etc/ssh/welcome.msg #Port 22 #AddressFamily any #ListenAddress 0.0.0.0 #ListenAddress :: # Disable legacy (protocol version 1) support in the server for new # installations. In future the default will change to require explicit # activation of protocol 1 Protocol 2 # HostKey for protocol version 1 #HostKey /etc/ssh/ssh_host_key # HostKeys for protocol version 2 #HostKey /etc/ssh/ssh_host_rsa_key #HostKey /etc/ssh/ssh_host_dsa_key # Lifetime and size of ephemeral version 1 server key #KeyRegenerationInterval 1h #ServerKeyBits 1024 # Logging # obsoletes QuietMode and FascistLogging #SyslogFacility AUTH #LogLevel INFO # Authentication: #LoginGraceTime 2m PermitRootLogin no #StrictModes yes #MaxAuthTries 6 #MaxSessions 10 #RSAAuthentication yes #PubkeyAuthentication yes #AuthorizedKeysFile .ssh/authorized_keys # For this to work you will also need host keys in /etc/ssh/ssh_known_hosts #RhostsRSAAuthentication no # similar for protocol version 2 #HostbasedAuthentication no # Change to yes if you don't trust ~/.ssh/known_hosts for # RhostsRSAAuthentication and HostbasedAuthentication #IgnoreUserKnownHosts no # Don't read the user's ~/.rhosts and ~/.shosts files #IgnoreRhosts yes # To disable tunneled clear text passwords, change to no here! #PasswordAuthentication yes #PermitEmptyPasswords no # Change to no to disable s/key passwords #ChallengeResponseAuthentication yes # Kerberos options #KerberosAuthentication no #KerberosOrLocalPasswd yes #KerberosTicketCleanup yes #KerberosGetAFSToken no # GSSAPI options #GSSAPIAuthentication no #GSSAPICleanupCredentials yes # Set this to 'yes' to enable PAM authentication, account processing, # and session processing. If this is enabled, PAM authentication will # be allowed through the ChallengeResponseAuthentication and # PasswordAuthentication. Depending on your PAM configuration, # PAM authentication via ChallengeResponseAuthentication may bypass # the setting of "PermitRootLogin without-password". # If you just want the PAM account and session checks to run without # PAM authentication, then enable this but set PasswordAuthentication # and ChallengeResponseAuthentication to 'no'. #UsePAM no #AllowAgentForwarding yes #AllowTcpForwarding yes #GatewayPorts no #X11Forwarding no #X11DisplayOffset 10 #X11UseLocalhost yes #PrintMotd yes #PrintLastLog yes #TCPKeepAlive yes #UseLogin no UsePrivilegeSeparation no #PermitUserEnvironment no Compression no ClientAliveInterval 15 ClientAliveCountMax 4 #UseDNS yes #PidFile /var/run/sshd.pid #MaxStartups 10 #PermitTunnel no #ChrootDirectory none # no default banner path #Banner none # override default of no subsystems Subsystem sftp /usr/libexec/sftp-server # Example of overriding settings on a per-user basis #Match User anoncvs # X11Forwarding no # AllowTcpForwarding no # ForceCommand cvs server Here the ssh client output: myself@ubuntu:~$ ssh -vvv [email protected] OpenSSH_6.6.1, OpenSSL 1.0.1f 6 Jan 2014 debug1: Reading configuration data /etc/ssh/ssh_config debug1: /etc/ssh/ssh_config line 19: Applying options for * debug2: ssh_connect: needpriv 0 debug1: Connecting to 192.168.1.1 [192.168.1.1] port 22. debug1: Connection established. debug3: Incorrect RSA1 identifier debug3: Could not load "/home/myself/.ssh/id_rsa" as a RSA1 public key debug1: identity file /home/myself/.ssh/id_rsa type 1 debug1: identity file /home/myself/.ssh/id_rsa-cert type -1 debug1: identity file /home/myself/.ssh/id_dsa type -1 debug1: identity file /home/myself/.ssh/id_dsa-cert type -1 debug1: identity file /home/myself/.ssh/id_ecdsa type -1 debug1: identity file /home/myself/.ssh/id_ecdsa-cert type -1 debug1: identity file /home/myself/.ssh/id_ed25519 type -1 debug1: identity file /home/myself/.ssh/id_ed25519-cert type -1 debug1: Enabling compatibility mode for protocol 2.0 debug1: Local version string SSH-2.0-OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.8 debug1: Remote protocol version 2.0, remote software version OpenSSH_5.6 debug1: match: OpenSSH_5.6 pat OpenSSH_5* compat 0x0c000000 debug2: fd 3 setting O_NONBLOCK debug3: load_hostkeys: loading entries for host "192.168.1.1" from file "/home/myself/.ssh/known_hosts" debug3: load_hostkeys: found key type RSA in file /home/myself/.ssh/known_hosts:26 debug3: load_hostkeys: loaded 1 keys debug3: order_hostkeyalgs: prefer hostkeyalgs: [email protected],[email protected],ssh-rsa debug1: SSH2_MSG_KEXINIT sent debug1: SSH2_MSG_KEXINIT received debug2: kex_parse_kexinit: [email protected],ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1 debug2: kex_parse_kexinit: [email protected],[email protected],ssh-rsa,[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,ssh-ed25519,ssh-dss debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,[email protected],[email protected],[email protected],aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,[email protected] debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,[email protected],[email protected],[email protected],aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,[email protected] debug2: kex_parse_kexinit: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-md5,hmac-sha1,[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-ripemd160,[email protected],hmac-sha1-96,hmac-md5-96 debug2: kex_parse_kexinit: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-md5,hmac-sha1,[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-ripemd160,[email protected],hmac-sha1-96,hmac-md5-96 debug2: kex_parse_kexinit: none,[email protected],zlib debug2: kex_parse_kexinit: none,[email protected],zlib debug2: kex_parse_kexinit: debug2: kex_parse_kexinit: debug2: kex_parse_kexinit: first_kex_follows 0 debug2: kex_parse_kexinit: reserved 0 debug2: kex_parse_kexinit: diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1 debug2: kex_parse_kexinit: ssh-rsa,ssh-dss debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,[email protected] debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,[email protected] debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,[email protected],hmac-ripemd160,[email protected],hmac-sha1-96,hmac-md5-96 debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,[email protected],hmac-ripemd160,[email protected],hmac-sha1-96,hmac-md5-96 debug2: kex_parse_kexinit: none debug2: kex_parse_kexinit: none debug2: kex_parse_kexinit: debug2: kex_parse_kexinit: debug2: kex_parse_kexinit: first_kex_follows 0 debug2: kex_parse_kexinit: reserved 0 debug2: mac_setup: setup hmac-md5 debug1: kex: server->client aes128-ctr hmac-md5 none debug2: mac_setup: setup hmac-md5 debug1: kex: client->server aes128-ctr hmac-md5 none debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<3072<8192) sent debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP debug2: bits set: 1481/3072 debug1: SSH2_MSG_KEX_DH_GEX_INIT sent debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY debug1: Server host key: RSA 91:66:c0:07:e0:c0:df:b7:8e:49:97:b5:36:12:12:ea debug3: load_hostkeys: loading entries for host "192.168.1.1" from file "/home/myself/.ssh/known_hosts" debug3: load_hostkeys: found key type RSA in file /home/myself/.ssh/known_hosts:26 debug3: load_hostkeys: loaded 1 keys debug1: Host '192.168.1.1' is known and matches the RSA host key. debug1: Found key in /home/myself/.ssh/known_hosts:26 debug2: bits set: 1551/3072 debug1: ssh_rsa_verify: signature correct debug2: kex_derive_keys debug2: set_newkeys: mode 1 debug1: SSH2_MSG_NEWKEYS sent debug1: expecting SSH2_MSG_NEWKEYS debug2: set_newkeys: mode 0 debug1: SSH2_MSG_NEWKEYS received debug1: SSH2_MSG_SERVICE_REQUEST sent debug2: service_accept: ssh-userauth debug1: SSH2_MSG_SERVICE_ACCEPT received debug2: key: /home/myself/.ssh/id_rsa (0x802b9240), debug2: key: /home/myself/.ssh/id_dsa ((nil)), debug2: key: /home/myself/.ssh/id_ecdsa ((nil)), debug2: key: /home/myself/.ssh/id_ed25519 ((nil)), debug3: input_userauth_banner debug1: Authentications that can continue: publickey,password,keyboard-interactive debug3: start over, passed a different list publickey,password,keyboard-interactive debug3: preferred gssapi-keyex,gssapi-with-mic,publickey,keyboard-interactive,password debug3: authmethod_lookup publickey debug3: remaining preferred: keyboard-interactive,password debug3: authmethod_is_enabled publickey debug1: Next authentication method: publickey debug1: Offering RSA public key: /home/myself/.ssh/id_rsa debug3: send_pubkey_test debug2: we sent a publickey packet, wait for reply debug1: Authentications that can continue: publickey,password,keyboard-interactive debug1: Trying private key: /home/myself/.ssh/id_dsa debug3: no such identity: /home/myself/.ssh/id_dsa: No such file or directory debug1: Trying private key: /home/myself/.ssh/id_ecdsa debug3: no such identity: /home/myself/.ssh/id_ecdsa: No such file or directory debug1: Trying private key: /home/myself/.ssh/id_ed25519 debug3: no such identity: /home/myself/.ssh/id_ed25519: No such file or directory debug2: we did not send a packet, disable method debug3: authmethod_lookup keyboard-interactive debug3: remaining preferred: password debug3: authmethod_is_enabled keyboard-interactive debug1: Next authentication method: keyboard-interactive debug2: userauth_kbdint debug2: we sent a keyboard-interactive packet, wait for reply debug1: Authentications that can continue: publickey,password,keyboard-interactive debug3: userauth_kbdint: disable: no info_req_seen debug2: we did not send a packet, disable method debug3: authmethod_lookup password debug3: remaining preferred: debug3: authmethod_is_enabled password debug1: Next authentication method: password [email protected]'s password: debug3: packet_send2: adding 64 (len 57 padlen 7 extra_pad 64) debug2: we sent a password packet, wait for reply debug1: Authentication succeeded (password). Authenticated to 192.168.1.1 ([192.168.1.1]:22). debug1: channel 0: new [client-session] debug3: ssh_session2_open: channel_new: 0 debug2: channel 0: send open debug1: Requesting [email protected] debug1: Entering interactive session. debug2: callback start debug2: fd 3 setting TCP_NODELAY debug3: packet_set_tos: set IP_TOS 0x10 debug2: client_session2_setup: id 0 debug2: channel 0: request pty-req confirm 1 debug1: Sending environment. debug3: Ignored env XDG_VTNR debug3: Ignored env MANPATH debug3: Ignored env XDG_SESSION_ID debug3: Ignored env CLUTTER_IM_MODULE debug3: Ignored env SELINUX_INIT debug3: Ignored env XDG_GREETER_DATA_DIR debug3: Ignored env COMP_WORDBREAKS debug3: Ignored env SESSION debug3: Ignored env NVM_CD_FLAGS debug3: Ignored env GPG_AGENT_INFO debug3: Ignored env TERM debug3: Ignored env SHELL debug3: Ignored env XDG_MENU_PREFIX debug3: Ignored env VTE_VERSION debug3: Ignored env NVM_PATH debug3: Ignored env GVM_ROOT debug3: Ignored env WINDOWID debug3: Ignored env UPSTART_SESSION debug3: Ignored env GNOME_KEYRING_CONTROL debug3: Ignored env GTK_MODULES debug3: Ignored env NVM_DIR debug3: Ignored env USER debug3: Ignored env LD_LIBRARY_PATH debug3: Ignored env LS_COLORS debug3: Ignored env XDG_SESSION_PATH debug3: Ignored env XDG_SEAT_PATH debug3: Ignored env SSH_AUTH_SOCK debug3: Ignored env SESSION_MANAGER debug3: Ignored env DEFAULTS_PATH debug3: Ignored env XDG_CONFIG_DIRS debug3: Ignored env PATH debug3: Ignored env DESKTOP_SESSION debug3: Ignored env QT_IM_MODULE debug3: Ignored env QT_QPA_PLATFORMTHEME debug3: Ignored env NVM_NODEJS_ORG_MIRROR debug3: Ignored env GVM_VERSION debug3: Ignored env JOB debug3: Ignored env PWD debug3: Ignored env XMODIFIERS debug3: Ignored env GNOME_KEYRING_PID debug1: Sending env LANG = en_US.UTF-8 debug2: channel 0: request env confirm 0 debug3: Ignored env gvm_pkgset_name debug3: Ignored env GDM_LANG debug3: Ignored env MANDATORY_PATH debug3: Ignored env IM_CONFIG_PHASE debug3: Ignored env COMPIZ_CONFIG_PROFILE debug3: Ignored env GDMSESSION debug3: Ignored env SESSIONTYPE debug3: Ignored env XDG_SEAT debug3: Ignored env HOME debug3: Ignored env SHLVL debug3: Ignored env GOROOT debug3: Ignored env LANGUAGE debug3: Ignored env GNOME_DESKTOP_SESSION_ID debug3: Ignored env DYLD_LIBRARY_PATH debug3: Ignored env gvm_go_name debug3: Ignored env LOGNAME debug3: Ignored env GVM_OVERLAY_PREFIX debug3: Ignored env COMPIZ_BIN_PATH debug3: Ignored env XDG_DATA_DIRS debug3: Ignored env QT4_IM_MODULE debug3: Ignored env DBUS_SESSION_BUS_ADDRESS debug3: Ignored env PrlCompizSessionClose debug3: Ignored env PKG_CONFIG_PATH debug3: Ignored env GOPATH debug3: Ignored env NVM_BIN debug3: Ignored env LESSOPEN debug3: Ignored env NVM_IOJS_ORG_MIRROR debug3: Ignored env INSTANCE debug3: Ignored env TEXTDOMAIN debug3: Ignored env XDG_RUNTIME_DIR debug3: Ignored env DISPLAY debug3: Ignored env XDG_CURRENT_DESKTOP debug3: Ignored env GTK_IM_MODULE debug3: Ignored env LESSCLOSE debug3: Ignored env TEXTDOMAINDIR debug3: Ignored env GVM_PATH_BACKUP debug3: Ignored env COLORTERM debug3: Ignored env XAUTHORITY debug3: Ignored env _ debug2: channel 0: request shell confirm 1 debug2: callback done debug2: channel 0: open confirm rwindow 0 rmax 32768 debug2: channel_input_status_confirm: type 99 id 0 debug2: PTY allocation request accepted on channel 0 debug2: channel 0: rcvd adjust 2097152 debug2: channel_input_status_confirm: type 99 id 0 debug2: shell request accepted on channel 0 Here the sshd server output: debug1: sshd version OpenSSH_5.6p1 debug1: read PEM private key done: type RSA debug1: private host key: #0 type 1 RSA debug1: read PEM private key done: type DSA debug1: private host key: #1 type 2 DSA debug1: rexec_argv[0]='/usr/sbin/sshd' debug1: rexec_argv[1]='-d' Set /proc/self/oom_adj from 0 to -17 debug1: Bind to port 22 on 0.0.0.0. Server listening on 0.0.0.0 port 22. socket: Address family not supported by protocol debug1: Server will not fork when running in debugging mode. debug1: rexec start in 4 out 4 newsock 4 pipe -1 sock 7 debug1: inetd sockets after dupping: 3, 3 Connection from 192.168.1.60 port 53445 debug1: Client protocol version 2.0; client software version OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.8 debug1: match: OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.8 pat OpenSSH* debug1: Enabling compatibility mode for protocol 2.0 debug1: Local version string SSH-2.0-OpenSSH_5.6 debug1: list_hostkey_types: ssh-rsa,ssh-dss debug1: SSH2_MSG_KEXINIT sent debug1: SSH2_MSG_KEXINIT received debug1: kex: client->server aes128-ctr hmac-md5 none debug1: kex: server->client aes128-ctr hmac-md5 none debug1: SSH2_MSG_KEX_DH_GEX_REQUEST received debug1: SSH2_MSG_KEX_DH_GEX_GROUP sent debug1: expecting SSH2_MSG_KEX_DH_GEX_INIT debug1: SSH2_MSG_KEX_DH_GEX_REPLY sent debug1: SSH2_MSG_NEWKEYS sent debug1: expecting SSH2_MSG_NEWKEYS debug1: SSH2_MSG_NEWKEYS received debug1: KEX done debug1: userauth-request for user user service ssh-connection method none debug1: attempt 0 failures 0 debug1: userauth_send_banner: sent Failed none for user from 192.168.1.60 port 53445 ssh2 debug1: userauth-request for user user service ssh-connection method publickey debug1: attempt 1 failures 0 debug1: test whether pkalg/pkblob are acceptable debug1: temporarily_use_uid: 0/0 (e=0/0) debug1: trying public key file //.ssh/authorized_keys debug1: Could not open authorized keys '//.ssh/authorized_keys': No such file or directory debug1: restore_uid: 0/0 debug1: temporarily_use_uid: 0/0 (e=0/0) debug1: trying public key file //.ssh/authorized_keys2 debug1: Could not open authorized keys '//.ssh/authorized_keys2': No such file or directory debug1: restore_uid: 0/0 Failed publickey for user from 192.168.1.60 port 53445 ssh2 debug1: userauth-request for user user service ssh-connection method keyboard-interactive debug1: attempt 2 failures 1 debug1: keyboard-interactive devs debug1: auth2_challenge: user=user devs= debug1: kbdint_alloc: devices '' Failed keyboard-interactive for user from 192.168.1.60 port 53445 ssh2 debug1: Unable to open the btmp file /var/log/btmp: No such file or directory debug1: userauth-request for user user service ssh-connection method password debug1: attempt 3 failures 2 Could not get shadow information for user Accepted password for user from 192.168.1.60 port 53445 ssh2 debug1: Entering interactive session for SSH2. debug1: server_init_dispatch_20 debug1: server_input_channel_open: ctype session rchan 0 win 1048576 max 16384 debug1: input_session_request debug1: channel 0: new [server-session] debug1: session_new: session 0 debug1: session_open: channel 0 debug1: session_open: session 0: link with channel 0 debug1: server_input_channel_open: confirm session debug1: server_input_global_request: rtype [email protected] want_reply 0 debug1: server_input_channel_req: channel 0 request pty-req reply 1 debug1: session_by_channel: session 0 channel 0 debug1: session_input_channel_req: session 0 req pty-req debug1: Allocating pty. debug1: session_pty_req: session 0 alloc /dev/pts/1 debug1: server_input_channel_req: channel 0 request env reply 0 debug1: session_by_channel: session 0 channel 0 debug1: session_input_channel_req: session 0 req env debug1: server_input_channel_req: channel 0 request shell reply 1 debug1: session_by_channel: session 0 channel 0 debug1: session_input_channel_req: session 0 req shell debug1: Setting controlling tty using TIOCSCTTY. /etc/pam.d/sshd: # PAM configuration for the Secure Shell service # Read environment variables from /etc/environment and # /etc/security/pam_env.conf. auth required pam_env.so # [1] # Standard Un*x authentication. auth include common-auth # Disallow non-root logins when /etc/nologin exists. account required pam_nologin.so # Uncomment and edit /etc/security/access.conf if you need to set complex # access limits that are hard to express in sshd_config. # account required pam_access.so # Standard Un*x authorization. account include common-accountt # Standard Un*x session setup and teardown. session include common-session # Print the message of the day upon successful login. session optional pam_motd.so # [1] # Print the status of the user's mailbox upon successful login. session optional pam_mail.so standard noenv # [1] # Set up user limits from /etc/security/limits.conf. session required pam_limits.so # Standard Un*x password updating. password include common-password
In the chat, it turned out the system was using traditional (non-shadow) password storage and traditional Unix password hashing algorithm. Both are poor choices in today's security environment. Since the traditional password hashing algorithm only stores and compares the first 8 characters of the password, that explains the behavior noticed in the original question. The posted sshd output includes the line: Could not get shadow information for user I would assume this means at least sshd (or possibly the PAM Unix password storage library) on this system includes shadow password functionality, but for some reason, the system vendor has chosen not to use it.
ssh - why can I login with partial passwords? [duplicate]
1,424,016,937,000
I want to do a passwordless ssh connection for a subversion project. Right now I'm using ssh+svn, and it's a little annoying, because I have to type the password any time I want to transact with the server. I've found several tutorials on the web about how to generate a key for passwordless ssh, but they all seem to assume that I'm using the same username on the remote system as I am for my home system. However, the username that I use for ssh+svn is different that the user account name on the system that I'm running. How do I set this up properly? I haven't had luck with just changing the name in the key file.
You just have to supply the other system's username in the svn command: $ svn co svn+ssh://otheruser@othersystem/path/to/repo To answer your question's title, too: $ ssh otheruser@othersystem This causes sshd on the remote machine to look in ~otheruser/.ssh/authorized_keys for the public key corresponding to the private key on the machine you're typing the command on.
passwordless ssh for another username?
1,424,016,937,000
I am trying to use Debian live from an USB, however I do not succeed in logging in… What is the standard user and password to get access? I have tried searching this question on the internet and used combinations of standard user credentials that I found such as live/live, root/root, root/live, and combinations without a password. None of them worked. This problem applies to Gnome, KDE, Xfce for me.
You could either try using user:live as username:password combination or adding live-config to the boot options (as suggested here: http://forums.debian.net/viewtopic.php?f=10&t=102937 ) which should log you in automatically.
Debian Live-CD user password
1,424,016,937,000
I've often created temporary passwords for users for my own development machine for initial id creation. For other environments, I've seen admins have the ability to have a password show as expired immediately, forcing me to change my password on first login. How does one do this? (In this specific case I am using RHEL, but I'm hoping this information is universal across all/most linux distros)
You can use the command chage -d 0 [username] to change the users expiration date, forcing them to change their password on first log in. You can read more about it in the man pages for chage and usermod.
How to expire a password? (For inital account creation)
1,424,016,937,000
I've been using the pass password manager for a year or so now, and it's awesome, but sometimes I like to test other password managers and then I need my passwords back. So far I've just been adding them manually as I need them, but if I want to migrate to another password manager I need a script, because I don't have the patience to do it one by one, considering I have near to a hundred (if not more). Is it possible? Is there already a solution? I've searched for a solution on and off for the past couple months and haven't been able to find one where it's "just run this script and boom exported". Is there such a script? If not, what or where should I look into to make one?
You can do this if you are running gpg-agent (and your passphrase is loaded), by looping through the files in your password store and writing them to a separate file. You do have to strip the leading directories from the path ($PASSWORD_STORE_DIR) and the .gpg extension from each of the files in the subdirectories, but otherwise it is straightforward enough: #!/usr/bin/env bash # export passwords to external file shopt -s nullglob globstar prefix=${PASSWORD_STORE_DIR:-$HOME/.password-store} for file in "$prefix"/**/*.gpg; do file="${file/$prefix//}" printf "%s\n" "Name: ${file%.*}" >> exported_passes pass "${file%.*}" >> exported_passes printf "\n\n" >> exported_passes done
Export passwords from the `pass` password manager
1,424,016,937,000
I am a Windows user gradually moving towards Linux. In Windows we have an option of either having or not having some password for a user. Once we do not put a password we can directly log in to the system. However, in Linux this is not possible as every user must have a password. Even if one does not give a password not typing anything and simply pressing the Return key doesn't log one in (unlike Windows). Is there some default password set for every user or any other mechanism by means of which a password is always assigned?
Authentication can be handled in many different ways in Linux. Password authentication via /etc/passwd and /etc/shadow is the usual default. There is no default password. A user is not required to have a password. In a typical setup a user without a password will be unable to authenticate with the use of a password. This is common for system users which are used to run daemons, but are not intended to be used directly by a human. You can configure Linux to allow login to the desktop automatically, or allow login without a password. Authentication is done via PAM, which is highly configurable. The Arch wiki offers the following PAM configuration for login without a password: If you want to bypass the password prompt in GDM then simply add the following line on the first line of /etc/pam.d/gdm-password: auth sufficient pam_succeed_if.so user ingroup nopasswdlogin Then, add the group nopasswdlogin to your system. See Groups for group descriptions and group management commands. Now, add your user to the nopasswdlogin group and you will only have to click on your username to login.
Is there some default password for a new user in Linux?
1,424,016,937,000
I must admit that I like servers without passwords in some cases. A typical server is vulnerable to anyone who has physical access to it. So in some cases it is practical to lock it physically and since then trust any physical access. Basic concepts In theory, when I physically reach such a server, I should be able to perform administration tasks without password by simply typing root as the login and I shouldn't be asked for a password. The same may apply to user accounts but one would not really access them physically. Therefore no system passwords are needed for (occasional) local access. When accessing the server remotely, either for administration, or for user account, I expect to always use an SSH private key. It is very easy to set up an SSH key for a just created account and thus no system passwords are needed for (regular) remote access. # user=... # # useradd -m "$user" # sudo -i -u "$user" $ keyurl=... $ $ mkdir -p .ssh $ curl -o .ssh/authorized_keys "$keyurl" The conclusion is that, in theory, we wouldn't neeed any system passwords for use cases like that. So the question is, how do we configure the system and user accounts to make it happen in a consistent and secure way. Local access details How do we ensure the root account can be accessed locally without a password? I don't think we can use passwd -d as that will make root access too permissive and an unpriviliged user could switch to root for free, which is wrong. We cannot use passwd -l as it prevents us from logging in. Note that local access is exclusively about access using the local keyboard. Therefore a valid solution must not allow any user switching (whether using su or sudo). Remote access details Until recently the above solution would work but now SSH started to check for locked user accounts. We cannot probably use passwd -d for the same reasons. We cannot use passwd -u as it just complains that it would lead to what passwd -d does. There's a workaround with dummy password for this part. user=... echo -ne "$user:`pwgen 16`\n" | chpasswd It might also be possible to turn off locked account checking in SSH entirely but it would be nicer to retain the support of locked accounts and just be able to unlock them. Final notes What I'm interested in is a solution that would allow you to log in to the root account locally and all accounts including root remotely, without any passwords. On the other hand, a solution must not impact security except in explicitly described ways, especially not by allowing remote users to get access to the root account or other users' account. The solution should be sufficiently robust so that it doesn't cause security issues indirectly. An accepted and awarded answer may or may not describe detailed configuration of individual tools but must contain the key points to reach the stated goals. Note that this probably cannot be solved through conventional use of tools like passwd, ssh, su, sudo and the like. More ideas after reading the first answers Just an idea – the local root access could be achieved by starting root shells instead of login processes. But there's still the need to lock only password authentication, not public key authentication.
Requirements for which I will offer solutions, as bullet points: Passwordless root console login Passwordless root remote login from pre-authorised users Passwordless remote login for specified accounts from pre-authorised users Passwordless remote login for any account from pre-authorised users The following examples are based on Debian, since that's what I've got here for testing. However, I see no reason why the principles cannot be applied to any distribution (or indeed any PAM-based *ix derivative). Passwordless root console login I think the way I would approach this would be to leverage PAM and the /etc/securetty configuration file. As a pre-requisite, a "sufficiently secure" root password must be set. This is not required for console login but exists to make brute force cracking attempts unrealistic. The account is otherwise a perfectly normal root account. In /etc/pam.d/login I have the following standard set of lines for authentication (those beginning with keyword auth): auth optional pam_faildelay.so delay=3000000 auth [success=ok new_authtok_reqd=ok ignore=ignore user_unknown=bad default=die] pam_securetty.so auth requisite pam_nologin.so @include common-auth auth optional pam_group.so The referenced common-auth include file contains the following relevant lines: auth [success=1 default=ignore] pam_unix.so nullok_secure auth requisite pam_deny.so auth required pam_permit.so auth optional pam_cap.so The common-auth file instructs PAM to skip one rule (the deny) if a "UNIX login" succeeds. Typically this means a match in /etc/shadow. The auth ... pam_securetty.so line is configured to prevent root logins except on tty devices specified in /etc/securetty. (This file already includes all the console devices.) By modifying this auth line slightly it is possible to define a rule that permits a root login without a password from a tty device specified in /etc/securetty. The success=ok parameter needs to be amended so that the ok is replaced by the number of auth lines to be skipped in the event of a successful match. In the situation shown here, that number is 3, which jumps down to the auth ... pam_permit.so line: auth [success=3 new_authtok_reqd=ok ignore=ignore user_unknown=bad default=die] pam_securetty.so Passwordless root remote login from pre-authorised users This is a straightforward inclusion of ssh keys for those authorised users being added to the root authorized_keys file. Passwordless remote login for specified accounts from pre-authorised users This is also a straightforward inclusion of ssh keys for authorised users being added to the appropriate and corresponding user's .ssh/authorized_keys file. (The typical remote user chris wants passwordless login to local user chris scenario.) Note that accounts can remain in the default locked state after creation (i.e. with just ! in the password field for /etc/shadow) but permit SSH key based login. This requires root to place the key in the new user's .ssh/authorized_keys file. What is not so obvious is that this approach is only available when UsePAM Yes is set in /etc/ssh/sshd_config. PAM differentiates ! as "account locked for password but other access methods may be permitted" and !... "account locked. Period." (If UsePAM No is set, then OpenSSH considers any presence of ! starting the password field to represent a locked account.) Passwordless remote login for any account from pre-authorised users It wasn't entirely clear to me whether you wanted this facility or not. Namely, certain authorised users would be able to ssh login without a password to any any every local account. I cannot test this scenario but I believe this can be achieved with OpenSSH 5.9 or newer, which permits multiple authorized_keys files to be defined in /etc/ssh/sshd_config. Edit the configuration file to include a second file called /etc/ssh/authorized_keys. Add your selected authorised users' public keys to this file, ensuring permissions are such that it is owned by root and has write access only by root (0644).
A consistent and safe approach to passwordless accounts with SSH
1,424,016,937,000
When you setup a new Ubuntu or OS X installation a user is generally created for you. On OS X it is whatever username you pick. On Ubuntu (the server version) usually the ubuntu user is created. The way I understand it, there is also a root user, which you can access via something like sudo su - root, and entering the password of the ubuntu or the user you created, which is part of the administrators group. Once you switch to root I think you can use the passwd command and change root's password. But what was root's password before that? Does it exist? Is it a random string of numbers and letters? How does the system deal with that?
I can answer only for Ubuntu. In Ubuntu the root user has a locked password. From passwd man page: -l, --lock Lock the password of the named account. This option disables a password by changing it to a value which matches no possible encrypted value (it adds a '!' at the beginning of the password). You can see the ! in /etc/shadow. A user with a locked account cannot change its password, but root can, without prior entering of the old password.
Is there a root password on OS X and Ubuntu?
1,424,016,937,000
On my personal machine, I often type sudo in front of certain commands in order to accomplish administrative tasks. I had hoped to avoid doing this throughout the day, by typing su root and providing the same password I usually do for sudo. However, the two passwords are not the same(I don't know how to log in to su root). Is running a command with sudo different than logging in with su root and running the same command? I think sudo and su root are the same, because when I type sudo whoami, I get root, as opposed to just whoami where I get my user-name.
Contrary to what their most common use would lead you to think, su and sudo are not just meant for logging in (or performing actions) as root. su allows you to switch your identity with that of someone else. For this reason, when you type su, the system needs to verify that you have the credentials for the target user you're trying to change into. sudo is a bit different. Using sudo allows you to run certain (or all, depending on the configuration) commands as someone else. Your own identity is used to determine what types of commands sudo will run for you under someone else's identity: if you're a trusted user (in the sense that the sysadmin trusts you), you'll be allowed more free rein than, say, an intern. This is why sudo needs to verify your own identity rather than that of the target user. In other words, trying to su to someone you're not is like attempting to charge your purchases to a stolen credit card while using sudo is like selling your friend's car by legal proxy. As for what you were trying to do, just sudo su root, or even more simply sudo su and type your regular user password. This would roughly amount to replacing your friend's credit card credentials with your own using the legal proxy they gave you :). It of course assumes the sudo configuration allows you to run su with escalated privileges. Also, systems that come pre-configured with sudo access typically have the root account disabled (no root password), you can enable that using the passwd command after becoming root via sudo su.
Why is the 'sudo' password different than the 'su root' password
1,426,405,492,000
I want the ssh command to only allow one chance in typing the password, if the password was wrong at the first time the ssh will return Permission denied (publickey......). Is there a flag that tells the ssh to request only once the password? Instead of: [nir@dhcppc4 ~]$ ssh [email protected] [email protected]'s password: Permission denied, please try again. [email protected]'s password: Permission denied, please try again. [email protected]'s password: Permission denied (publickey.....). I want: [nir@dhcppc4 ~]$ ssh [email protected] [email protected]'s password: Permission denied (publickey.....). The solution must be on the client side (e.g. some flag to the ssh command or using pipeline), I can't touch sshd_config, or any other system config file. Because -in general- I build 3rd party software (so I can't generate keys nor config system files) that access the servers in the LAN, the passwords are saved in the DB (therefore doesn't need second attempt). And in my code if I'll be able to assume that I only have one attempt to ssh/scp it will simplify the relevant code.
In the sshd config man page man 5 sshd_config: MaxAuthTries Specifies the maximum number of authentication attempts permitted per connection. Once the number of failures reaches half this value, additional failures are logged. The default is 6. So a setting of MaxAuthTries 2 will be the setting you will need. sshd will need to be restarted afterwards (has to be ran as root): /etc/init.d/ssh restart or service ssh restart On the client side this can set with ssh settings (look at man 5 ssh_config for the settings you can apply): NumberOfPasswordPrompts Specifies the number of password prompts before giving up. The argument to this keyword must be an integer. The default is 3. So edit your ~/.ssh/config file and add: Host <name_or_ip_of_host|*> NumberOfPasswordPrompts 1 Where <name_or_ip_of_host|*> the canonical IP or hostname you are using on the command line, or * for all host connection attempts. You can also specify this on the command line without having to edit your /.ssh/config file: ssh -o NumberOfPasswordPrompts=1 user@hostname
How to disable the try again password in ssh command
1,426,405,492,000
When applying sudo to a command which doesn't actually need sudo, sometimes it doesn't ask me for my password. For example under my $HOME, sudo ls. But I remember that it does for some other command, though I forget which one. So I was wondering how sudo decides whether to ask for a password, when given a command which doesn't actually need sudo? Is there some rule in /etc/sudoers specifying that? My real problem is that when I use du, it sometimes shows "permission denied" for some directories, and sometimes not, probably because I don't have permission on some directories? I apply sudo to du regardless, and thought I would be asked for a password regardless, but actually not on my own directories.
In a typical configuration, the command is irrelevant. You need to enter your password the first time you use sudo, and you don't need your password in that particular shell for the next 15 minutes. From the computer's perspective, there is no such thing as a “command that needs sudo”. Any user can attempt to run any command. The outcome may be nothing but an error message such as “Permission denied” or “No such file or directory”, but it's always possible to run the command. For example, if you run du on a directory tree that has contents that you don't have permission to access, you'll get permission errors. That's what “permission denied” means. If you run sudo du, sudo runs du as root, so you don't get permission errors (that's the point of the root account: root¹ always has permission). When you run sudo du, du runs as root, and sudo is not involved at all after du has started. Whether du encounters permission errors is completely irrelevant to how sudo operates. There are commands that need sudo to do something useful. Usefulness is a human concept. You need to use sudo (or some other methods to run the command as root) if the command does something useful when run as root but not when run under your account. Whether sudo asks for your password depends on two things. Based on the configuration, sudo decides whether you need to be authenticated. By default, sudo requires a password. This can be turned off in several ways, including setting the authenticate option to false and having an applicable rule with the NOPASSWD tag. If sudo requires your password, it may be content to use a cached value. That's ok because the reason sudo needs your password is not to authenticate who's calling it (sudo knows what user invoked it), but to confirm that it's still you at the commands and not somebody who took control over your keyboard. By default, sudo is willing to believe that you're still at the commands if you entered your password less than 15 minutes ago (this can be changed with the timeout option). You need to have entered the password in the same terminal (so that if you remain logged in on one terminal then leave that terminal unattended and then use another terminal, someone can't take advantage of this to use sudo on the other terminal — but this is a very weak advantage and it can be turned off by setting the tty_tickets option to false). ¹ nearly, but that's beyond the scope of this thread.
How does sudo decide whether to ask for a password, when given a command which doesn't actually need `sudo`?
1,426,405,492,000
In my case, I have a situation that I'm trying to send a file via SCP using sshpass but I can't. I need to use a script with a password but the easiest way doesn't work on the hostName2 I have no possibility to see configuration sshd_config etc. and send ssh-copy-id, I need use 'myPass' look at this: sshpass -p 'myPass' ssh -p 2122 [email protected] ^ OK sshpass -p 'myPass' scp ~/myDir/testPB.txt [email protected]:/chroot/tomcat/testPB ^NOT OK It works fine: [tomcat@hostName .ssh]$ sshpass -p 'myPass' ssh -p 2122 [email protected] Last login: Mon Aug 22 11:41:32 2016 from xxx.xxx.xx.xxx ################# # hostName2 # ################# JAVA_HOME=/opt/java TOMCAT_HOME = /chroot/tomcat LOG = /log/tomcat , /log/apache LOG_ARCH = /log/arch/tomcat , /log/arch/apache STATS = /log/stats and there is a problem: [tomcat@hostName .ssh]$ sshpass -p 'myPass' scp -vvv ~/myDir/testPB.txt [email protected]:/chroot/tomcat/testPB Executing: program /usr/bin/ssh host 195.182.52.175, user tomcat, command scp -v -t /chroot/tomcat/testPB OpenSSH_5.3p1, OpenSSL 1.0.1e-fips 11 Feb 2013 debug1: Reading configuration data /etc/ssh/ssh_config debug1: Applying options for * debug2: ssh_connect: needpriv 0 debug1: Connecting to xxx.xxx.xx.xxx [xxx.xxx.xx.xxx] port 22. debug1: Connection established. debug1: identity file /home/tomcat/.ssh/identity type -1 debug1: identity file /home/tomcat/.ssh/identity-cert type -1 debug3: Not a RSA1 key file /home/tomcat/.ssh/id_rsa. debug2: key_type_from_name: unknown key type '-----BEGIN' debug3: key_read: missing keytype debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug3: key_read: missing whitespace debug2: key_type_from_name: unknown key type '-----END' debug3: key_read: missing keytype debug1: identity file /home/tomcat/.ssh/id_rsa type 1 debug1: identity file /home/tomcat/.ssh/id_rsa-cert type -1 debug1: identity file /home/tomcat/.ssh/id_dsa type -1 debug1: identity file /home/tomcat/.ssh/id_dsa-cert type -1 debug1: identity file /home/tomcat/.ssh/id_ecdsa type -1 debug1: identity file /home/tomcat/.ssh/id_ecdsa-cert type -1 ssh_exchange_identification: Connection closed by remote host lost connection what's wrong?
You use an alternative port with ssh -p 2122 but not with scp. Try sshpass -p 'myPass' scp -P 2122 ~/myDir/testPB.txt [email protected]:/chroot/tomcat/testPB Please note upper case P. As per man scp: -P port Specifies the port to connect to on the remote host.  Note that this option is written with a capital ‘P’, because -p is already reserved for preserving the times and modes of the file in rcp(1).
sshpass with SSH works, but sshpass with SCP doesn't [closed]
1,426,405,492,000
Basically the entire question is in the headline: Does ssh send the password over the network? Presuming of course that login via username and password is used. I'm asking because if ssh doesn't send the password over the network, a man in the middle can't get the user's password even if the user adds the alleged host to their known_hosts file. Someone said it has to, so I wrote down a counter example in a comment. Since the question of how else it could possibly work now came up repeatedly, I'm copying that comment here. The server can tell the client which hash to use. [The same one which is used to hash the passwords in the server's shadow file.] The client can then calculate the hash ψ which should be in the server's shadow file but let's call the one on the server ψ'. So both the server and the client know ψ. The client can then pick a random salt σ an send (hash(ψ.σ), σ) (where . is the concatenation operator) to the server. The server then hashes ψ'.σ and checks whether the first element of the tuple it received from the client matches that hash. If it does, the client knows the password.
If you're using password authentication, then SSH sends the password over the network. The connection is encrypted, so eavesdroppers can't see the password. The connection is authenticated, provided that you don't click blindly through a “The authenticity of … can't be established” message, so your password won't be sent to anyone except the legitimate server. The boring answer to “why” is that this is what the SSH protocol requires. The less boring answer is that password authentication has to work that way. There are ways to perform authentication that don't work this way but this is no longer simple password authentication. Most authentication protocols that are more advanced than simple password authentication have the nice property that the client doesn't send any secret data to the server that a malicious server could use to impersonate the user on some third server. With SSH public key authentication, the most common SSH authentication method other than passwords, this works because the client sends a signature (requiring the private key) of data that includes the session identifier; if the malicious server tried to authenticate to a third server, it would have to generate a signature of data including a different session identifier, which it would be unable to do without the private key that stays on the client. Note that if you use public key authentication, and you have to type a password to use the key, this is not password-based authentication. The password to use the key is used exclusively on the client side, to read the key from the key file. When using public key authentication, the server does not know or care whether the key was stored in an encrypted file. Password authentication requires sending the password to the server. Sending a hash of the password instead of the password itself does not help, because then the password becomes the hash: an attacker wouldn't need to find the actual password, only the hash. An attacker could attack by finding the actual password, so there is no improvement. But if the attacker found the hash but not the password, in your proposed scheme, that would be enough. In contrast, with normal password-based authentication, the attacker must know the password, knowing the hash is not good enough, and if the password is strong enough then the attacker won't be able to find the password from the hash. In practice, the reason the attacker might know the hash but not the password is that the attacker managed to extract the database of password hashes from the server, possibly from an unprotected backup or via a vulnerability on the server. Such vulnerabilities on websites make the news pretty often. Your proposed protocol is less good than the standard one. Don't roll your own crypto!
Does ssh send the password over the network?
1,426,405,492,000
I have done this: sudo chown -R myname /usr/ and now I can't use the sudo command because of this error: sudo: must be setuid root And as I read this means that the owner of this file /usr/bin/sudo is not the root. It's my user now because of the chown on the /usr folder. On many forums and blogs people suggest to do this as root: # chown root:root /usr/bin/sudo # chmod 4111 /usr/bin/sudo ...but the problem with this is that I need to log in as a root, but I can't because If I write su in the terminal the password is wrong (actually I use the password what I added to my user): $ su Password: su: Authentication failure So can I get back the sudo command? Edit: My Ubuntu is under Paralells on my Mac OS X.
If you have a similar system that you can use as a guide to see what the correct ownership for all of the files is, then you can boot into rescue mode, drop to a root shell, and manually restore the correct ownership to all of the files in /usr. The quickest way may be to reinstall your OS or restore from backup. In Ubuntu or similar, then there is no root password by default (the account is disabled), which is why you can't su.
How to get back sudo on Ubuntu?
1,426,405,492,000
How do I log into my Linux laptop if I have forgotten both the username and password?
You can drop into single mode from Grub. During boot press Esc on the Grub boot screen when it prompts you to. It may just show you Grub with listings of each kernel - if that's the case don't press Esc. From here select the first entry and press e to edit that entry. Page down to the line that starts with kernel and press e again. This will allow you to edit the entire line. Scroll to the right until you reach the end and remove splash quiet from the line, replacing it with single. Press Enter to accept the changes and press b to boot into the modified kernel line. This will boot you into single user mode and should drop you into a root shell once the boot has completed. From here you can add users to the system, change user passwords, etc.
How do I log into my Linux laptop if I have forgotten both the login and password?
1,426,405,492,000
On my Fedora 20 system I use scp a lot, and this is the second time I encounter this. When I run this command: scp -r -P PORT user@host:/home/user/something/{file1,folder1,folder2,folder3,folder4} folder/folder2/ it asks me for the password for each file/directory it transfers. user@host's password: "password here" Question: What is happening here? Is this normal, I would think this is very peculiar behavior?
Your local shell (probably bash) is expanding user@host:/home/user/something/{file1,folder1,folder2,folder3,folder4} into: user@host:/home/user/something/file1 user@host:/home/user/something/folder1 user@host:/home/user/something/folder2 user@host:/home/user/something/folder3 user@host:/home/user/something/folder4 Instead, you can do: scp -r -P PORT user@host:"/home/user/something/file1 /home/user/something/folder1 /home/user/something/folder2 /home/user/something/folder3 /home/user/something/folder4" folder/folder2/ or, if you know user's login shell on the remote end is bash, you can use brace expansion too: scp -r -P PORT user@host:"/home/user/something/{file1,folder1,folder2,folder3,folder4}" folder/folder2/ to have the remote shell split the string into arguments instead of the local shell.
SCP command with selected file and directories for download asks for password for each new file or directory
1,426,405,492,000
I am going to write a simple replacement for Ubunutu's NetworkManager. Is there any place where the Wifi network passwords would be stored in Linux? I know about /etc/NetworkManager/nm-system-settings.conf If not, can I store them safely somewhere using some builtin OS utilities?
Ubuntu (and most likely many flavors of Debian) stores the information at /etc/NetworkManager/system-connections. Each of the connections has its own file entry. The files are secured with file mode 600 and owned by root. The files in this directory are not limited to wireless connections; there are files for the wired connections, too.
Where does Linux store Wifi passwords?
1,426,405,492,000
So I'm setting up a WordPress backup guide/making a backup schedule for myself for real. I want to do MySQL dumps daily, but the command either requires -p then user input or --password="plain text password" Could I pass it to a file that is atleast MD5 or better hashed and protected to increase security but make the command require no user input? Any help is appreciated! For Reference here is the command I want to run mysqldump -u [username] --password=~/wp_backups/sqldumps/.sqlpwd [database name] > ~/wp_backups/sqldumps/"$(date '+%F').sql"
You have following password options: provide the password on the command line through the -p option provide the password via the MYSQL_PWD environment variable put your configuration in the ~/.my.cnf file under the [mysqldump] section In all cases your client needs a plain text password to be able to authenticate. You mentioned hashes, but the trait of a hash is that it's a one way conversion function (i.e. you won't be able to restore the original password from a hash), therefore it's unusable as the authentication token. Since you are backing up the Wordpress database from, allegedly, the same account that hosts your Wordpress there is no security improvements of trying to hide the password from the user that runs Wordpress (the database credentials can be easily extracted from the wp-config.php file anyway). So, I'd suggest to define the following ~/.my.cnf: [mysqldump] host = your_MySQL_server_name_or_IP port = 3306 user = database_user_name password = database_password Then ensure that the file has the 0600 permissions. This way mysqldump does not need any database credential specified on its command line (they will be read from the ~/.my.cnf file.
MySQLdump via crontab - Pass --password=/hashed/password/file so I can use via crontab w/o using plain text password
1,426,405,492,000
I'm using the command line tool pwgen to generate passwords because I love the repeatability you get with the sha1 command line flag. To quote the man page: -H, --sha1=/path/to/file[#seed] Will use the sha1's hash of given file and the optional seed to create password. It will allow you to compute the same password later, if you remember the file, seed, and pwgen's options used. ie: pwgen -H ~/your_favorite.mp3#[email protected] gives a list of possibles passwords for your pop3 account, and you can ask this list again and again. WARNING: The passwords generated using this option are not very random. If you use this option, make sure the attacker can not obtain a copy of the file. Also, note that the name of the file may be easily available from the ~/.history or ~/.bash_history file. I'm using it to generate (and retrieve) passwords like this: pwgen -1cnsy --sha1=/path/to/my/gpg/private-key.asc#[email protected] The only problem is that I can't figure out a way to specify how many characters I want the password to be. By default it generates an 8-character password, which is more susceptible to brute-forcing. Alternatively, I could use apg, which allows me to specify the number of characters, but I don't see a way to make apg take a file and string as a seed to give me repeatable characters. Is there a way I can make pwgen generate passwords of a specified length?
Usage: pwgen [ OPTIONS ] [ pw_length ] [ num_pw ] Thus: pwgen -1cnsy --sha1=/path/to/my/gpg/private-key.asc#[email protected] 42 Beware that pwgen will happily print a password that's as long as you request, but beyond a certain point (determined by the entropy of the specified file) that doesn't increase security.
Can pwgen output passwords of a certain length?
1,426,405,492,000
When it comes to passwd/user-password-crypted statement in a preseed file, most examples use an MD5 hash. Example: # Normal user's password, either in clear text #d-i passwd/user-password password insecure #d-i passwd/user-password-again password insecure # or encrypted using an MD5 hash. #d-i passwd/user-password-crypted password [MD5 hash] From Debian's Appendix B. Automating the installation using preseeding. A few sources show that it's also possible to use SHA-512: Try using a hashed password like this: $ mkpasswd -m sha-512 [...] And then in your preseed file: d-i passwd/user-password-crypted password $6$ONf5M3F1u$bpljc9f1SPy1w4J2br[...] From Can't automate user creation with preseeding on AskUbuntu. This is slightly better than MD5, but still doesn't resist well against brute force and rainbow tables. What other algorithms can I use? For instance, is PBKDF2 supported, or am I limited by the algorithms used in /etc/shadow, that is MD5, Blowfish, SHA-256 and SHA-512?
You can use anything which is supported in the /etc/shadow file. The string given in the preseed file is just put into /etc/shadow. To create a salted password to make it more difficult just use mkpasswd with the salt option (-S): mkpasswd -m sha-512 -S $(pwgen -ns 16 1) mypassword $6$bLyz7jpb8S8gOpkV$FkQSm9YZt6SaMQM7LPhjJw6DFF7uXW.3HDQO.H/HxB83AnFuOCBRhgCK9EkdjtG0AWduRcnc0fI/39BjmL8Ee1 In the command above the salt is generated by pwgen.
What hash algorithms can I use in preseed's passwd/user-password-crypted entry?
1,426,405,492,000
I moved to the pass password manager and I'm trying to integrate it as well as possible into my workflow. However, I'm not familiar with deeper synchronization/version-control concepts (git, password server), so I'm stuck syncing the passwords between multiple computers. I'm using Linux (Debian 9) and the synchronization is done over the local network with Unison -- usually I'm indicating which directories should be the same and every time, before I switch, I'm syncing between the machines. Is there a possibility to sync the password-store directories – and how, considering the keys are required to use pass. Alternatively is there a good -- easy to understand and complete -- tutorial for using the git-/server-solution? (The official manual, article1, article2, article3 I found are incomplete for normal users.)
I've followed the step by step instructions of Mathew Robinson here and it works like a charm. The linked article recommends making a git repository for the password store and using pass git push origin master to sync. Then use gpg2 --export-secret-keys > [name].gpg to put your gpg key in a file, which you should move to the new machine. Then on the new machine you can gpg2 --import [name].gpg and pass commands work normally.
'pass': Easiest way to synchronize the password-store between multiple machines
1,426,405,492,000
I have an external hdd partitioned into two. One of the partitions has Linux (Ubuntu) installed on it (bootable). The thing is I have forgotten the password of it's user (single user). How can I reset the password of user by plugging the external hdd to another Linux machine and then editing some file, using some command through terminal, changing the bash(remember doing something similar long time ago), or something else? And I do not want to get into Grub etc. Booting through that drive is not an option (although it is but I am not willing to get into it and don't want to restart the running("another") Linux machine).
Even though michas gave you the optimal answer, it still involves booting from the external hard drive, which for some reason you seem against. Here's a method you can use from another Linux system without booting from the external drive. I assume that your Linux partition on the external HDD is /dev/sdb1, modify the following as needed. Run this code on your other Linux installation: [root@host]# mount /dev/sdb1 /mnt [root@host]# chroot /mnt [root@host]# passwd user Enter new Unix password: Retype new Unix password: passwd: password updated successfully [root@host]# exit [root@host]# umount /mnt
Resetting password of another Linux