Hot answers tagged

248

How about using the su command? $ whoami user1 $ su - user2 Password: $ whoami user2 $ exit logout If you want to log in as root, there's no need to specify username: $ whoami user1 $ su - Password: $ whoami root $ exit logout Generally, you can use sudo to launch a new shell as the user you want; the -u flag lets you specify the username you want: $ ...


123

Some commands (eg chown) can accept either a username or a numeric user ID, so allowing all-numeric usernames would break that. A rule to allow names that start with a number and contain some alpha was probably considered not worth the effort; instead there is just a requirement to start with an alpha character. Edit: It appears from the other responses ...


87

On Debian, the adduser package contains a deluser program which removes a user from a group if you pass both as arguments: deluser user group If your distribution doesn't have adduser, you can edit /etc/group and /etc/gshadow manually. vigr vigr -s


76

There's probably an easier way, but I do this: See who's logged into your machine -- use who or w: > who mmrozek tty1 Aug 17 10:03 mmrozek pts/3 Aug 17 10:09 (:pts/2:S.0) Look up the process ID of the shell their TTY is connected to: > ps t PID TTY STAT TIME COMMAND 30737 pts/3 Ss 0:00 zsh Laugh at their ...


74

here is a test on ubuntu 14.04 using numbers: root@ubuntu:~# useradd 232 root@ubuntu:~# mkdir /home/232 root@ubuntu:~# chown 232.232 /home/232 root@ubuntu:~# passwd 232 Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully root@ubuntu:~# login c2 login: 232 Password: Welcome to Ubuntu 14.04.4 LTS (GNU/Linux 4.4.0-22-...


59

passwd -l 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). passwd -u will undo it.


47

Try usermod --move-home --login <new-login-name> --home <new-home-dir> <old-login-name> The --move-home option moves the old home directory's contents to the new one given by the --home option which is created if it doesn't already exist. If you want the primary user group to match the new-login-name, add --gid <new-login-name> to ...


41

Well, OpenSSH private keys with empty passphrases are actually not encrypted. Encrypted private keys are declared as such in the private key file. For instance: -----BEGIN RSA PRIVATE KEY----- Proc-Type: 4,ENCRYPTED DEK-Info: DES-EDE3-CBC,7BD2F97F977F71FC BT8CqbQa7nUrtrmMfK2okQLtspAsZJu0ql5LFMnLdTvTj5Sgow7rlGmee5wVuqCI /clilpIuXtVDH4picQlMcR+...


40

The devil is in the details, in the useradd man page (you can see that by issuing man 8 useradd): -u, --uid UID The numerical value of the user's ID. This value must be unique, unless the -o option is used. The value must be non-negative. The default is to use the smallest ID value greater than or equal to UID_MIN and greater ...


40

First off, the respective man page snippets highlight the differences between the two commands and give some indication of what is going on. For adduser: adduser and addgroup add users and groups to the system according to command line options and configuration information in /etc/adduser.conf. They are friendlier front ends to the low level ...


36

id -u somename returns a non-zero exit code when the user does not exist. You can test it quite simply... (&>/dev/null just supresses the normal output/warning) id -u somename &>/dev/null || useradd somename


36

ulimit is made for this. You can setup defaults for ulimit on a per user or a per group basis in /etc/security/limits.conf ulimit -v KBYTES sets max virtual memory size. I don't think you can give a max amount of swap. It's just a limit on the amount of virtual memory the user can use. So you limits.conf would have the line (to a maximum of 4G of ...


35

That is not a technical difference but an organizational decision. E.g. it makes sense to show normal users in a login dialog (so that you can click them instead of having to type the user name) but it wouldn't to show system accounts (the UIDs under which daemons and other automatic processes run) there. Thus a border is defined or rather two ranges for ...


32

For the same reasons why each daemon should have minimal rights. Apache can run as root. It is designed to perform one task and surely nothing bad can happen? But assume apache is not bug-free. Bugs are discovered from time to time. Sometimes it can even be arbitrary code execution or similar. Now with apache running as root, it can access anything — for ...


31

There is a utility which will lookup user information regardless of whether that information is stored in local files such as /etc/passwd or in LDAP or some other method. It's called getent. In order to get user information out of it, you run getent passwd $USER. You'll get a line back that looks like: [jenny@sameen ~]$ getent passwd jenny jenny:*:1001:...


30

When booting, append init=/bin/bash (or a path to any other functional shell) to your boot options - you will be dropped straight to a single user shell. You might need to do mount -o remount,rw / before modifying the /etc/passwd entry in that environment. After that, just reboot or do exec /sbin/init 3. Just do not type exit or press Ctrl+D, as these would ...


29

The correct way according to usermod(8) is: usermod --lock --expiredate 1970-01-01 <username> (Actually, the argument to --expiredate can be any date before the current date in the format YYYY-MM-DD.) Explanation: --lock locks the user's password. However, login by other methods (e.g. public key) is still possible. --expiredate YYYY-MM-DD ...


29

Add the following in your ~/.ssh/config file: Host myserver.cz User tohecz Host anotherserver.cz User anotheruser You can specify a lot of default parameters for your hosts using this file. Just have a look at man ssh_config for other possibilities.


28

Local solution: use su yourself to login again. In the new session you'll be considered as a member of the group. Man pages for newgrp and sg might also be of interest to change your current group id (and login into a new group): To use webdev's group id (and privileges) in your current shell use: newgrp webdev To start a command with some group id (...


28

If you take a look at the nologin man page you'll see the following description. excerpt nologin displays a message that an account is not available and exits non-zero. It is intended as a replacement shell field to deny login access to an account. If the file /etc/nologin.txt exists, nologin displays its contents to the user instead of ...


28

Use the psql shell and: \deu[+] [PATTERN] such as: postgres=# \deu+ List of user mappings Server | User name | FDW Options --------+-----------+------------- (0 rows) And for all users: postgres=# \du List of roles Role name | Attributes | Member of ------------+---------------...


27

As Micheal already pointed out, you can use who to find out who's logged in. However if they have multiple processes, there's a more convenient way than killing each process individually: you can use killall -u username to kill all processes by that user.


27

You can also ride a motorcycle in the nude, and nothing may happen. But I bet you'd feel better if you had when you crash the bike...


27

Try getent passwd "$uid" | cut -d: -f1


26

From https://github.com/zolrath/wemux: wemux enhances tmux to make multi-user terminal multiplexing both easier and more powerful. It allows users to host a wemux server and have clients join in either: Mirror Mode gives clients (another SSH user on your machine) read-only access to the session, allowing them to see you work, or Pair Mode ...


26

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 ...


25

Generally you use sudo to launch a new shell as the user you want; the -u flag lets you specify the username you want: [mrozekma@etudes-1 ~] % whoami mrozekma [mrozekma@etudes-1 ~] % sudo -u nobody zsh [nobody@etudes-1 ~] % whoami nobody There are more circuitous ways if you don't have sudo access, like ssh username@localhost, but I think sudo is probably ...


25

usermod -G "" username removes all secondary/supplementary groups from username, leaving them as a member of only their primary group. this worked in Solaris 5.9


24

Definitely it serves a security purpose. For example, look at the below bug filed for a system user who had a shell. My debian server was compromised due to the daemon account having a valid login shell and having samba open for internet access. The break in was made by setting a password remotly via samba for the daemon account and the logging ...



Only top voted, non community-wiki answers of a minimum length are eligible