How to Set Up Passwordless SSH Between Two Linux Servers

SSH key authentication lets you log in from one Linux server to another without typing a password, which is essential for scripts, backups, and automation. Here’s how to set it up between server1 and server2.

1. Generate a Key Pair on server1

ssh myusername@server1
ssh-keygen -t rsa

Press Enter at each prompt to accept the defaults (leave the passphrase empty for fully passwordless logins). You’ll see output like this:

Generating public/private rsa key pair.
Enter file in which to save the key (/home/local/myusername/.ssh/id_rsa):
Created directory '/home/local/myusername/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/local/myusername/.ssh/id_rsa.
Your public key has been saved in /home/local/myusername/.ssh/id_rsa.pub.
The key fingerprint is:
15:68:47:67:0d:40:e1:7c:9a:1c:25:18:be:ab:f1:3a myusername@server1

Display the public key and copy it. Make sure it stays on one line when you copy it; line breaks will stop the key from working.

cd .ssh
cat id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAyFS7Ykakcjdy...== myusername@server1

2. Add the Public Key on server2

ssh myusername@server2
mkdir .ssh
cd .ssh
vi authorized_keys
# paste the public key, then save
chmod 600 authorized_keys

3. Test It

ssh myusername@server1
ssh myusername@server2
# you should not be prompted for a password!

Tip: on most modern systems, ssh-copy-id myusername@server2 does step 2 for you in one command.

How to Enable Automatic Logon (AutoAdminLogon) on Windows Server

Windows Server can log a user on automatically at startup, which is useful for kiosks, lab machines, or servers that must run an app in an interactive session. This follows Microsoft’s registry method for turning on AutoAdminLogon.

Security note: this stores the password in plain text in the registry. Use it only where that risk is acceptable.

Steps to Turn On Automatic Logon

  1. Click Start → Run, type Regedt32.exe, and press Enter.
  2. Go to this key:
    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon
  3. Double-click DefaultUserName, enter the user name, and click OK.
  4. Double-click DefaultPassword, enter the password, and click OK. If DefaultPassword doesn’t exist, create it: Edit → New → String Value, name it DefaultPassword, then set the password. Without a DefaultPassword value, Windows automatically switches AutoAdminLogon from 1 back to 0, disabling it.
  5. Create another string value with Edit → New → String Value, name it AutoAdminLogon, and set it to 1.
  6. Close Registry Editor and restart the computer. It will now log on automatically.

Notes and Troubleshooting

  • Log on as someone else: hold down Shift after you log off or while Windows restarts to bypass automatic logon.
  • Logon banners break it: automatic logon won’t work if a logon banner (legal notice) is set by Group Policy or local policy. Exclude the server from that policy and it works as expected.
  • DefaultUserName gets overwritten: when a different user logs on at the console, Windows saves them as DefaultUserName, and AutoAdminLogon can then fail because the user and password no longer match. A shutdown script that resets DefaultUserName fixes this. See Microsoft KB 119364, “AutoAdminLogon loses DefaultUserName”.

Fix “Unable to find the binary installation directory (answer BINDIR)” When Reinstalling VMware Tools

If a previous VMware Tools installation on a Linux guest was botched, the installer may refuse to uninstall it and abort the new install.

The Error

A previous installation of VMware Tools has been detected.
The previous installation was made by the tar installer (version 4).

Keeping the tar4 installer database format.

You have a version of VMware Tools installed. Continuing this install will
first uninstall the currently installed version. Do you wish to continue?
(yes/no) [yes]

Answering yes produces:

Error: Unable to find the binary installation directory (answer BINDIR)
in the installer database file "/etc/vmware-tools/locations".
Uninstall failed. Please correct the failure and re run the install.

Execution aborted.

The Fix

Remove the corrupted installer database file, then run the VMware Tools installer again:

rm /etc/vmware-tools/locations
./vmware-install.pl

If the reinstall then complains about existing kernel modules, see fixing the clobber error when reinstalling VMware Tools.

Fix the “Clobber” Error When Reinstalling VMware Tools on Linux

When you reinstall or upgrade VMware Tools on a Linux guest, the installer can stop with an error about existing kernel modules (such as vmxnet, vmci, or pvscsi) that it won’t overwrite. Tell it to replace them with the --clobber-kernel-modules option.

From the extracted vmware-tools-distrib folder, run:

./vmware-install.pl --clobber-kernel-modules=vmxnet,vmci,vmxnet3,pvscsi,vmmemctl

Related: installing VMware Tools on CentOS.

Cloning WordPress from Dev to Production: The Search-Replace DB Tool

I spent days beating my head against the wall trying to move WordPress data between my development environment and production, using VMware clones and various other methods. The trouble is that WordPress stores its site URL all through the database, including inside serialized data, so a simple find-and-replace breaks things.

Then I found the Search Replace DB tool from Interconnect/IT, which made the job much easier. It safely updates URLs and paths across the whole database, serialized data included.

Search and Replace for WordPress Databases (Interconnect/IT)

Give it a look and see what you think. Delete the script from your server when you’re done, since it gives full database access.

WSUS Low Disk Space? Clean Up and Move the Content Folder and SUSDB Database

WSUS (Windows Server Update Services) can quickly fill a drive. Here are three ways to fix low disk space: run the Server Cleanup Wizard, move the content directory, and move the SUSDB database to another drive.

1. Run the WSUS Server Cleanup Wizard

  1. In the WSUS administration console, select Options → Server Cleanup Wizard.
  2. By default it removes unneeded content and computers that haven’t contacted the server in 30 days or more. Select all options and click Next.
  3. When it finishes, review the summary and click Finish.

2. Move the WSUS Content Directory

  1. Create a new content folder on another drive.
  2. Open a Command Prompt and go to the WSUS Tools folder, typically C:\Program Files\Update Services\Tools.
  3. Run the command below, where NewContentPath is the new folder and MoveLog is the path and file name for the log.
wsusutil movecontent NewContentPath MoveLog

For more on WSUSUtil, see “Managing WSUS 3.0 from the Command Line” in the WSUS Operations Guide.

3. Move the SUSDB Database

  1. Open a Command Prompt and stop the WSUS service: net stop wsusservice
  2. Detach the SUSDB database.
  3. Copy SUSDB.mdf and SUSDB_log.ldf to the new location.
  4. Attach SUSDB from the new location.
  5. Start the service again: net start wsusservice
  6. Once everything is working, delete the old SUSDB.mdf and SUSDB_log.ldf.

How to Configure Port Mirroring (SPAN) on a Dell Force10 S50 Switch

Port mirroring copies the traffic from one switch port to another so you can capture it with a network analyzer like Wireshark. Here I mirrored all traffic sent and received on port 0/48 of a Dell Force10 S50V switch to port 0/44 on the same switch.

Prepare the Destination Port

The destination port (0/44) doesn’t need to belong to any VLAN. It only needs no ip address and no shutdown configured.

Create the Monitor Session

enable
config
monitor session 0
source gigabitethernet 0/48 destination gigabitethernet 0/44 direction both

Mirroring a Port-Channel (LAG)

Once a link aggregation group is set up, you can mirror the whole port-channel instead by changing monitor session 0 to:

source port-channel 128 destination gigabitethernet 0/44 direction both

How to Shadow a VMware View (Horizon) PCoIP Desktop Session from vSphere

Unlike Citrix XenApp, VMware View has no central way to shadow a user’s desktop session, for example from the View Connection Server. It’s one of the most common questions from customers running View. You can, however, view a PCoIP session from the vSphere console by enabling one Group Policy setting.

Requirements

  • VMware vSphere 5 and VMware View 5 or later (vSphere 4 needs a registry hack instead).
  • Windows 7 desktops must use virtual hardware version 8. Windows XP and Vista can use any hardware version.

Steps to Enable PCoIP Session Shadowing

  1. Create a new Group Policy Object (GPO).
  2. Add the pcoip.adm template to Computer Configuration. You’ll find it on the View Connection Server in C:\Program Files\VMware\VMware View\Server\extras\GroupPolicyFiles.
  3. Enable Enable access to PCoIP session from a vSphere console under Computer Configuration.
  4. Link the GPO to the OU where the View desktops live.
  5. Let the domain controllers sync, then restart the View desktop.

You can now watch the PCoIP session from the vSphere console. Keyboard and mouse activity appears on both screens at the same time, with a slight delay.

Security note: the user isn’t asked to approve the shadow session, so consider the privacy implications before enabling this.

Locked Out of WordPress by Google Authenticator? How to Get Back In

I recently locked myself out of my WordPress site while experimenting with the Google Authenticator two-factor plugin. The fix is to disable the plugin over FTP, log in, and then turn it back on.

Steps to Disable the Plugin and Log In

  1. Connect to your site with an FTP or SFTP client and open /wp-content/plugins/google-authenticator.
  2. Rename the folder from google-authenticator to _google-authenticator. WordPress can no longer find it, so the plugin is disabled.
  3. Log in to WordPress as normal and open the Plugins page.
  4. Back in FTP, rename _google-authenticator back to google-authenticator.
  5. Refresh the Plugins page. The plugin now shows as deactivated. Reactivate it and reconfigure it in your user profile.

Avoid Locking Yourself Out Next Time

Before you enable two-factor authentication, create a second admin account without it. Test everything with your main account, and once it all works, delete the backup admin account. There’s a helpful video walkthrough of this approach here (video 3 on the page): Installation Essentials for WordPress.

How to Change the Remote Desktop (RDP) Listening Port in Windows

Remote Desktop listens on TCP port 3389 by default. You can move it to a different port with a quick registry change, which is handy for running several hosts behind one public IP or cutting down on automated scans.

Steps to Change the RDP Port

  1. Open Registry Editor (regedit).
  2. Go to this key and select the PortNumber value:
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp\PortNumber
  1. On the Edit menu, click Modify, then select Decimal.
  2. Type the new port number and click OK.
  3. Close Registry Editor and restart the computer.

Before You Connect

Allow the new port through Windows Firewall (and any network firewall) first, or you’ll lock yourself out. When connecting with Remote Desktop Connection, add the port to the address, for example server.example.com:3390.