Let’s dive a little deeper into some more commands, building on what we just explored.
To list all users in the system open up the following file:
# vim /etc/passwd
If it’s not quite clear, the idea is Linux allows you to have multiple users. Remember in these tutorials we’ve been logging in as the “root” user, but you can also login as other users, which perhaps have less permission to read and edit files. If you have other developers in your team you will want to only give them access to the files they’re working on. Also note to more experienced linux users why i recommend using “root” to start: the reason is because it removes complication and makes it so new Linux users have less to learn. Eventually they’ll learn about using the “sudo” command to preface their commands. For now, guys, google what “sudo” is.
To create a group type:
# groupadd groupname
To list all user groups open up the /etc/group file:
# vim /etc/group
To list all a specific user’s groups type:
# groups username
To add a new user type:
# adduser username
To add new users to a group type (this will also create the user):
# usermod -a -G groupname,groupname,groupname username
To change an existing user’s primary group type:
# usermod -g groupname username
The benefit of using groups is that you can designate permissions by group, and therefore give access (or remove access) to a folder for a many users all at the same time. That’s the general idea of groups in programming in genera--it allows you to do less work by making the code you write function on behalf of a group. Then you simply need a mechanism to assign users to groups. Above are the standard user grouping mechanisms of Linux.
To update your Ubuntu installation, type:
# apt-get update
To install an application (as you saw in the server Setup tutorials) type:
# apt-get install app-name
# apt-get install lamp-server^
To backup and restore MySQL databases use the following commands. First backup:
That will log you into your MySQL application (aided by a complementary application called “mysqldump”) and make a backup of the database called “database_name” and save it in a file called “backup-file.sql” in your current working directory.
Now here’s how you restore that backup:
# mysql -u user_name -pYourPassword database_name < backup-file.sql
That will log you directly into MySQL and immediately restore the contents of “backup-file.sql” to the database named “database_name”.
One key gotcha about these commands which fooled me the first (and second and probably third) times I used them was that the “-p” parameter has the password attached to it with no space in between like the “-u” username parameter.
Another cool feature I’ll just describe now is you can actually log into remote databases on a different server and restore their contents into your own database on your server. For example:
That will make a backup on the remote server and then “pipe” the results of that command via the “|” symbol into a second command, specifically the mysql command and create a new database and fill it with the results taken from the remote server.
Piping one command into another FYI is a key tool to use at the Linux command line. All these commands have output, and if that output is suitable as input to another command, just put a pipe in between. You can continue that process of “piping” one command to another as long as makes sense for what you’re trying to accomplish. You can also use an arrow (“>”) to pass any output to a text file or use the double arrow (“>>”) to append the text output at the end of the file without replacing what’s already there. That’s very useful for tracking the results of your commands.