Technology

Systems administrator tips: 5 aliases you can use at the command line

Posted by Pixafy Team

Systems administrators commonly use the command line to complete various tasks on a server. Many times we run a string of commands at once, or want a specific variable included automatically. In Linux, we can create an alias, which is a command that runs a set string of commands and variables. I’m going to list a few of my favorite ones, and why I like them:

  1. alias ssh=’ssh -A’This alias automatically adds ssh key agent forwarding when I type ssh. It’s a good way to avoid forgetting to add agent forwarding. Agent forwarding allows me to continue using my ssh key instead of a password.
  2. alias root=’ssh -A -lroot’This alias is the same as the one above but includes using root as the user I try to login as. This make a a quick login as root always ready in case I need to change a system file on a remote server.
  3. alias sshx=’ssh -X -A’This alias is the same as the first one, but has the added benefit of turning on X11 forwarding, so I can run GUI applications on the remote server, but have the window appear on my local workstation. This requires some extra setup on your local system (For Macs you just need to install the free XQaurtz tool) This is very handy if you want to configure a remote server application but it requires using a GUI tool to do so.
  4. alias mdate=’date +%m%d%G%H%M’mdate adds the proper variables to the date command to produce an output in the DDMMYYYYHHmm format. You can use mdate as part of a backup script to append the current date/time to a file.Ex: mysqldump -u root –password=yaysecurepassword database > database_`mdate`.sql
  5. alias publicip=’curl ifconfig.me’This alias displays the public IP of the server you are on. That would be the IP address your server appears to be coming from if it were to visit a website for example. It could be useful for scripting, or just as a quick way to find out what IP you are using if you manage many servers.

I hope these are useful to you, but if you have others you like to use, share them with me in the comments section!

Questions or comments? Share them below, or tweet us @Pixafy!

Tags