Putty Generate Ssh Key Command Line
Basic SSH (PuTTY) commands help you to navigate and work efficiently with the files in Linux terminal. In this article, We’d handpicked a list of PuTTY commands, their options, and usage.
- Generate Ssh Key Github
- Putty Generate Ssh Key Command Line Windows 10
- Generate Ssh Key Windows
- Use Putty Command Line
- Putty Command Prompt
What is SSH (PuTTY) Commands?
To generate the public/private key pair, enter this in the Command Prompt: ssh-keygen At the first prompt, “Enter file in which to save the key,” press Enter to save it in the default location. All Mac and Linux systems include a command called ssh-keygen that will generate a new key pair. If you're using Windows, you can generate the keys on your server. Just remember to copy your keys to your laptop and delete your private key from the server after you've generated it. To generate an SSH key pair, run the command ssh-keygen.
The Secure Shell (SSH) Protocol lets a user connect to a remotely located computer from one computer. This communication takes place through a secured encryption process. This kind of connection can be used for file transfer and issuing other remote commands. The SSH Protocol follows a client-server model in which connection is established by SSH Client to the SSH server. The SSH client uses public key cryptography to ensure a safe connection to the SSH server. After setting up the connection, the SSH client also ensures that the privacy and integrity of data are maintained throughout the network by using symmetric encryption, asymmetric encryption, and hashing algorithms.
The client-server based model of SSH commands or PuTTY commands allows the authentication of two remotely located systems while encrypting the data that passes through them. By default, SSH operates on TCP port 22, but it can be changed if required. The client connects with the server by performing a TCP handshake with the server, which is for verifying whether the information provided by the user matches with the previous record of information that is stored in an RSA key store file. Before establishing a connection, both the client and the server have to agree upon the encryption standards to ensure safe and secured communication and then the user must perform the authentication check.
Now, to make use of PuTTY commands, a terminal emulator that connects the client to the server is required. Openssl rsa_generate_key example. PuTTY is one such emulator which is open-source and free to download. Also, windows don’t have a pre-installed SSH server or client. So, the prerequisites for being able to use SSH (PuTTY) commands are as follows:
- A Linux based server that you would be connecting to.
- PuTTY for facilitating the connection process.
- The server’s IP address that acts as the location of the server to which you are trying to connect.
- Username and Password to make sure that you are authorized to connect to the server.
Connecting through PuTTY
Generate Ssh Key Github
- To connect to the server, enter the IP address of the server to the Host Name or IP address bar as shown in the image and keep the port as 22 and connection type as SSH. You may also save the configuration for further use.
- The PuTTY terminal will now open, asking for username and password to connect.
- You will be logged on the server you are trying to make a connection to.
If you using a Linux or Mac based Operating System, you don’t need a client like PuTTY as Linux has its own SSH terminal. You just need to use the following command to connect to the server:
ssh user@serverip
This command will connect you to a server whose IP address is “serverip”. “User” is the username that is authorized to connect to the server.
On entering the above command, you will be prompted to enter the password.
To close the connection to the remote server, just type “exit” on the terminal window. It will get you back to your local machine.
List of Basic PuTTY Commands
Now, to manage and operate on a Linux server, one must master the basic 17 SSH commandsto make the most use out of it. Let us look into some of the basic commands of SSH communication.
- pwd: As soon as you are logged into the server, the first and foremost thing to check would be the present location you are at. The command “pwd” takes care of that. Just type “pwd” and hit enter.
- cd: Now, you are at a location and you want to navigate to another. Type “cd /location” and you will reach that location. It stands for “change directory”.
- “cd .” makes you stay at the same directory you are at.
- “cd .” makes you shift one directory back. For example, you are at “/home/task/files” and you type “cd.” and hit enter. This will move you to “home/task”.
- “cd -” makes you go to the previous location you were at. For example, you were at “/home” but you moved to “/dir”. Typing “cd-” command will take you back to “/home”.
- “cd ~” will take you to your home directory and “cd /” will take you to root directory.
- mkdir: It stands for make directory and as the name suggest, it helps you with making a new directory with the name you choose at your current directory path.Syntax: mkdir directoryName
- ls: It stands for list command which is used to display all the contents in a folder or directory. “ls /home/folder” will enlist all the content inside the “folder” directory.
- “ls -a” will show you all the files in a directory”.
- “ls -h” will show the files while showing their sizes as well.
- “ls -r” will recursively show the subdirectories of the directory
- “ls -alh” will show you more details about the files contained in a folder. The details include the user permissions, last updated date, date of creation, time and the permission allotted to it like read, write and update.
- cp: It stands for copy command that basically copies a file in Linux.Syntax: cp filename.extension /dir/filename.extensionThe above command will copy the file “filename.extension” (source) and keep it to the location /dir (destination) with the same file name.
- “cp -r” copies all the contents of a folder.
- To copy and rename, use the command “cp filename.extension /dir/filename1.extension”. The file “filename.extension” will be copied to “filename1.extension present at /dir location.
- “cp -f” will force the copy process by deleting the destination file if a file with the same name happens to be there at the destination.
- “cp -i” will give you a warning message before actually proceeding with the copying process.
- “cp -u” will update the file in the destination folder only if the files have different content.
- “cp -n” will first check if the file already exists and if it does, it just won’t copy. It doesn’t overwrite the file.
- “cp -a” will archive the file.
- mv: The move command moves the file from one place to another instead of copying it, leaving no signs of the file in the source folder.Syntax: mv filename.extension /dir/filename.extension.
- To move and rename a file, use the command “mv filename.extension /dir/filename1.extension”.
- You can also move your file one folder back by using the command “mv filename/ .”.
- touch: Using “touch” command, you can create a new file with any extension you want like text, php, html, etc in your current directory. You can also create a file without any extension at all.Syntax: touch filename.extension
- rm: The remove command lets you delete a file from the server.Syntax: rm filename.extension
- “rm * foldername” will delete all the files or content in a directory.
- “rmdir” will remove the complete directory or folder.
- “rm -r foldername” will delete the folder as well as the folders inside it.
- cat: This command is used to display content of a file on the screen. It copies standard input to standard output. This command also allows scrolling if the displayed text doesn’t fit the screen completely.Syntax: cat filename.extension
- The cat command is also used to concatenate two files and show their content combined as one.
Syntax: cat file1.txt file2.txt > mergedfile.txt
“>” is the output redirection character - The cat command can also be used to create a new file.
Syntax: cat > filename.extension
- The cat command is also used to concatenate two files and show their content combined as one.
- head: The head command lets you read the first ten lines of the content inside a file.Syntax: head filename.extension
- You can also give the names of more than one file in the head command and it will show the first ten lines of each file separately.
Syntax: head /dir/file1 /var/file2 - You can also change the number of lines you want to be displayed on the screen rather than the default first ten lines.
Syntax: head -n15 /temp/filename
The above command will display the first fifteen lines of content from the given file.
- You can also give the names of more than one file in the head command and it will show the first ten lines of each file separately.
- tail: Just like the head command gives you the first ten lines, tail command gives you the last ten lines of content from the file.Syntax: tail filename.extension
- Also, you can provide multiple file names to the tail command for it to show last ten lines from each of the mentioned file.
Syntax: tail /dir/file1 /dir/file2 - Similar to the head command, the tail command also allows you to change the number of lines you want to be displayed other than the default number.
Syntax: tail -n15 /temp/filename
The above command will display the last fifteen lines of content from the given file.
- Also, you can provide multiple file names to the tail command for it to show last ten lines from each of the mentioned file.
- zip: A compression and file packaging utility in unix, zip command compression the file size. It also puts one or more files into a single zip archive.Syntax: zip -r foldername.zip foldername
- Using the command “zip -d filename.zip filename”, you can delete the file from the zip archive.
- Using the command “zip -u filename.zip filename”, the specified list of files can be updated in the zip archive.
- “zip -m filename.zip filename” deletes the original file after creating its zip archive.
- unzip: The unzip command is used to decompress a file.Syntax: unzip filename.zip
- You can unzip multiple numbers of files at a time by using the command “unzip file1.zip file2.zip file3.zip”.
- You can also exclude one or more files from unzipping.
Syntax: unzip filename.zip -x excludedfile.zip
The above command will extract all the files from the compressed archive except excludefile.zip.
- tar: It stands for tape archive. Also used to compress and decompress folders.Syntax: Command for compressing, that creates an archive for “folder”.tar -czvf folder1.tar.gz folderThe command for decompressing
tar -xvf folder1.tar.gz - chmod: chmod stands for change mode. Using this command, you can change permissions of a file or directory. These permissions can be represented either by numbers from 0 to 7 or with alphanumeric characters. 4 represents reading permission, 2 represents writing permission, 1 represents executing permission and 0 represents no permission.Syntax: chmod 754 filename
- In the above command, 7,5,4 represents the permission for the user, group and others wherein 7 is the combination of 4,2 and 1, which indicates all the three permissions are given to the user.
- Similarly, 5 is the combination of 4, 0 and 1, which indicates read, no write and execute permission.
- Also, 4 is the combination of 4, 0 and 0, which indicates read, no write and no execute permission.
- “chmod -r” lets you change the permission of a folder and all the files inside it as well.
- grep: If you want to search for a particular string inside a file or folder, grep is the right command for you. It returns the whole line containing the phrase if it finds the perfect match.
Syntax: grep “string” filename- The option i in the command “grep -i “string” filename” lets you search for a string case-insensitively in the file.
- You can count the number of appearances of a string in the given file by using the command “grep -c “string” filename”.
- You can display the filename that contains a particular pattern or string using the command “grep -l “string” *”.
- You can also display the line number along with the result using the command “grep -n “string” filename”.
- find: This command searches for a file inside a folder. Files with specific criteria can also be filtered out using this command. You can run find command to find files by permissions, users, groups, file type, size etc.Syntax: find . -name filename.extensionThe above command will find all the files with the name “filename.extension” in the current directory.
- If you want to find a file in some directory, use the command “find /directory -name filename.extension”.
- You can look for any type of file, say a php file by using the command “find . type f -name filename.php”.
- vi: The vi command lets you enter a text editor.Syntax: vi filename
The above command will open the file on the screen and if the file doesn’t exist, it will create a new one with the same name.- The escape key lets you cancel any command you have started in the vi editor mode.
- To exit the vi editor, type “:q”, only if you haven’t done any changes to the file.
- If you want to discard the changes you have done to the file, type “:q!” to exit.
So, these are some of the basic SSH (PuTTY) commands that come very handy for a user to manage the basic functionalities and handle files and folders on a Linux web server.
Related
Introduction
You have seen in previous tutorials how to use PuTTY to connect to your VPS securely and how to create SSH keys with PuTTYgen.
You might have more than one SSH key for a single cloud server, or simply more than one cloud server or Droplet that requires SSH keys to log into. This can make you feel overwhelmed with having to manage, sort out, and link all those keys to their respective servers. That’s why Pageant exists.
Pageant is a PuTTY authentication agent. It holds your private keys in memory so that you can use them whenever you are connecting to a server. It eliminates the need to:
Putty Generate Ssh Key Command Line Windows 10
- Explicitly specify the relevant key to each Linux user account, if you use more than one account to log into a server
- Type a key’s passphrase each time you log into your user account; and your keys should be passphrase protected since having an unprotected key is as good as hiding your password under your keyboard!
Prerequisites
Make sure you have these prerequisites.
- Pageant is installed together with the PuTTY suite; if you don’t have it installed, you can download it here
- You should already have at least one SSH key saved on your local computer
Step 1 — Adding Keys to Pageant
Start Pageant from the PuTTY folder: Start-Menu > All Programs > PuTTY > Pageant
Pageant starts by default minimized in the system tray. To begin adding your SSH keys, you should right click on its icon and then the following context menu will show up:
Clicking on Add Key from the menu or View Keys to open up the Pageant Key List window. Here you can view, add, and remove keys:
Tip: You can access the Pageant Key List window directly by double-clicking its icon in the system tray.
Click the Add Key button. This will open the file explorer, where you can choose one or more keys at a time to load. You should select files with the .ppk extension:
Click the Open button to load the keys with Pageant.
If a key is passphrase-protected, you will be prompted to enter the passphrase only once before it can be added to the Pageant Key List:
After successfully adding a key, you can now see it listed:
Step 2 — Connecting to the Server(s)
Now these keys will be available while connecting to any server during your PuTTY sessions. You don’t have to take any extra steps in PuTTY. Just enter your hostname or IP address, and SSH user. PuTTY will automatically try to authenticate using any keys currently loaded in Pageant.
Generate Ssh Key Windows
Step 3 (Optional) — Removing Keys from Pageant
If you want to remove a key from Pageant, select that key from the Pageant Key List window and press the Remove Key button. You can also remove multiple keys together by selecting them with CTRL or SHIFT.
Tips & Tricks
Use these tips to automate your authenticated connections with Pageant.
Loading Keys Automatically on Pageant Startup
You can make Pageant automatically load one or more private keys when it starts up, instead of adding them manually every time you start up Pageant.
Go to the Pageant shortcut icon from the Windows Start Menu or your desktop.
Right click on the icon, and click on Properties.
A new window will open containing the shortcut’s properties:
Use Putty Command Line
From the Shortcut tab, edit the Target field. Leave the path to pageant.exe intact. After that path, add paths to your .ppk key files. These should be outside the quotation marks. Here’s an example:
Click the Apply and then OK buttons.
Note: If the keys are encrypted, Pageant will request the passphrases on startup.
Making Pageant Run PuTTY
You can make Pageant start PuTTY or any other program once it has initialized itself and loaded any keys specified on its command line. That way you can just start Pageant instead of having to start both programs.
You can achieve this by following the same steps we used previously to add the keys automatically (see the previous section). Just add the program’s path at the end of the command in the Target field, preceded by the -c option, and contained within double quotes. Here’s an example of the full line for the Target field:
Putty Command Prompt
Other PuTTY Suite Products
Here are a few other helpful applications that can work with PuTTY.
- PuTTYgen: A tool to generate and edit SSH public and private key pairs. It is part of the PuTTY suite, but it can also operate with the private key formats used by some other SSH clients like WinSCP
- PSFTP: An interactive text-based client for the SSH-based SFTP (secure file transfer) protocol, that allows you to run an interactive file transfer session and perform many thing like listing the contents of directories, browsing around the file system, issuing multiple get and put commands, etc.
- PSCP (PuTTY Secure Copy Client): A tool for transferring files securely between computers using an SSH connection