Find the answer to your Linux question:
Results 1 to 5 of 5
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Bash scripting - modifying /etc/passwd

    Hi all,

    I have to write a program that asks the user for an account name on the system. It has to determine whether the account exists or not (it searches the /etc/passwd file for the account). If the account does not exist, it will display "account does not exist!" and ask for another account. If the account does exist, it will ask some informational questions about that account (i.e. a name, a location, and an extension number) and is to then add these items to that user's /etc/passwd entry.

    For example:

    Enter account:


    Enter name:

    Enter location:

    Enter number:

    admin:503:503:Administrator, Earth, 1234:/home/admin:/bin/bash

    So the last line is the modified /etc/passwd entry for the account 'admin'. This is what I am trying to accomplish. I have the program made, I just do not know how to modify the /etc/passwd entry (using bash scripting) for the user's information (name,location and number). Help is greatly appreciated! Thanks!


  2. #2
    Linux Engineer khafa's Avatar
    Join Date
    Apr 2008
    Tokyo, Japan

    try the command vipw.
    man vipw
    Linux and me it's a love story

  3. #3

    Modifying comment field

    You can use the chfn command to modify the field

    If the user is test1 as below

    You could modify it as below
    chfn -f "Test Account" -o "Earth"

    The entry now looks like below:
    test1:503:503:Test Account,Earth:/home/test1:/bin/bash

    If you're doing this for multiple users you can add the username at the end and run using sudo or as root.

  4. $spacer_open
  5. #4
    thanks knighster! this seems to work. however, can this only work on the current account, or am I able to change another user's finger information? I need to make it so it enters the account to be changed. can I do this? thanks!


  6. #5
    nevermind, i just realized you add the user to the end of the command, haha! thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts