This is the development version of Kanrisuru. Since this is still a pre-1.0 release, we don't recommend using this in system-critical production environments.

Kanrisuru

update_user

Updates a user in ruby.
linux manual

Basic Usage

require 'kanrisuru'
host = Kanrisuru::Remote::Host.new(host: '127.0.1.1', username: 'ubuntu', keys: ['~/.ssh/id_rsa'])

result = host.update_user('kanrisuru', uid: 3452, groups: ['disk', 'daemon'], append: true) 
result.success?
true

result.uid
3452

result.groups.map(&:name)
["kanrisuru", "daemon", "disk", "sudo", "admin", "ubuntu"]

Parameters

Field Type Description
user string
Required name of the user to update.
uid integer
The numerical value of the user's ID. This value must be unique, unless the non_unique option is used.
group string
The group name or number of the user's new initial login group. The group must exist. Any file from the user's home directory owned by the previous primary group of the user will be owned by this new group. The group ownership of files outside of the user's home directory must be fixed manually.
groups array
A list of supplementary groups which the user is also a member of.
append boolean
Add the user to the supplementary group(s).
shell string
The name of the user's login shell. The default is to leave this field blank, which causes the system to select the default login shell specified by the SHELL variable in /etc/default/useradd, or an empty string by default.
non_unique boolean
Allow the creation of a user account with a duplicate (non-unique) UID.
home string
The new user will be created using HOME_DIR as the value for the user's login directory. The default is to append the LOGIN name to BASE_DIR and use that as the login directory name.
movehome boolean
Move the content of the user's home directory to the new location. If the current home directory does not exist the new home directory will not be created.
password string
The encrypted password, as returned by crypt(3). The default is to disable the password.
expires string
The date on which the user account will be disabled. The date is specified in the format YYYY-MM-DD.

Result

Returns a single User struct.

User Fields

Field Type Description
uid integer The numerical value of the user's ID.
name string The name of the user
shell Kanrisuru::Core::User::FilePath The name of the user's login shell.
home Kanrisuru::Core::User::FilePath Location of the users home directory.
groups array Array of UserGroup structs, that define the all the groups a user belongs to.

Return Example

result = host.update_user('kanrisuru', uid: 3452, groups: ['disk', 'daemon'], append: true)
result.data
#<Struct:Kanrisuru::Core::User::User:0x00000bb8
  groups = [
    [0] #<Struct:Kanrisuru::Core::User::UserGroup:0x00000c08
      gid = 1005,
      name = "kanrisuru"
    >,
    [1] #<Struct:Kanrisuru::Core::User::UserGroup:0x00000c58
      gid = 1,
      name = "daemon"
    >,
    [2] #<Struct:Kanrisuru::Core::User::UserGroup:0x00000ca8
      gid = 6,
      name = "disk"
    >,
    [3] #<Struct:Kanrisuru::Core::User::UserGroup:0x00000cf8
      gid = 27,
      name = "sudo"
    >,
    [4] #<Struct:Kanrisuru::Core::User::UserGroup:0x00000d48
      gid = 116,
      name = "admin"
    >,
    [5] #<Struct:Kanrisuru::Core::User::UserGroup:0x00000d98
      gid = 1000,
      name = "ubuntu"
    >
  ],
  home = #<Struct:Kanrisuru::Core::User::FilePath:0x00000de8
    path = "/home/kanrisuru"
  >,
  name = "kanrisuru",
  shell = #<Struct:Kanrisuru::Core::User::FilePath:0x00000e60
    path = "/bin/bash"
  >,
  uid = 3452
>

Exit Status

Code Description
0 Success

Tested On

  • Ubuntu, Debian, Centos, Fedora, Redhat, OpenSuse, SLES