This page is about the OpenSSH Practically every Unix and Linux system includes the SSH Command in Linux Other SSH Commands Using the Linux client Specifying a different user name Executing remote commands on the server SSH client configuration file Configuring public key authentication Configuring port forwarding SSH command line options A little history The There are other SSH commands besides the client ssh-keygen - creates a key pair for public key authentication ssh-copy-id - configures a public key as authorized on a server ssh-agent - agent to hold private key for single sign-on ssh-add - tool to add a key to the agent scp - file transfer client with RCP-like command interface sftp - file transfer client with FTP-like command interface sshd - OpenSSH server Linux typically uses the OpenSSH client. The ssh command to log into a remote machine is very simple. To log in to a remote computer called sample.ssh.com, type the following command at a shell prompt: If this is the first time you use ssh to connect to this remote machine, you will see a message like: Type Each server has a host key, and the above question related to verifying and saving the host key, so that next time you connect to the server, it can verify that it actually is the same server. Once the server connection has been established, the user is authenticated. Typically, it asks for a password. For some servers, you may be required to type in a one-time password generated by a special hardware token. Once authentication has been accepted, you will be at the shell prompt for the remote machine. It is also possible to use a different username at the remote machine by entering the command as: The above can also be expressed with the syntax: The ssh command is often also used to remotely execute commands on the remote machine without logging in to a shell prompt. The syntax for this is: For example, to execute the command: on host sample.ssh.com, type the following command at a shell prompt: After authenticating to the remote server, the contents of the remote directory will be displayed, and you will return to your local shell prompt. -x Disables X11 forwarding. The To configure passwordless public key authentication, you may want to create an SSH key and set up an authorized_keys file. See the pages on ssh-keygen and ssh-copy-id for more information. Command-line options can be used to set up port forwarding. Local fowarding means that a local port (at the client computer) is tunneled to an IP address and port from the server. Remote forwarding means that a remote port (at the server computer) is forwarded to a given IP address and port from the client machine. See the page on configuring port forwarding on how to configure them. OpenSSH also supports forwarding Unix domain sockets and IP packets from a tunnel device to establish a VPN (Virtual Private Network). Some of the most important command-line options for the OpenSSH client are: -1 Use protocol version 1 only. -2 Use protocol version 2 only. -4 Use IPv4 addresses only. -6 Use IPv6 addresses only. -A Enable forwarding of the authentication agent connection. -a Disable forwarding of the authentication agent connection. -C Use data compression -c cipher_spec Selects the cipher specification for encrypting the session. -D -E log_file Append debug logs to log_file instead of standard error. -F configfile Specifies a per-user configuration file. The default for the per-user configuration file is ~/.ssh/config. -g Allows remote hosts to connect to local forwarded ports. -i identity_file A file from which the identity key (private key) for public key authentication is read. -J -l login_name Specifies the user to log in as on the remote machine. -p port Port to connect to on the remote host. -q Quiet mode. -V Display the version number. -v Verbose mode. -X Enables X11 forwarding. SSH replaced several older commands and protocols in Unix and Linux the 1990s. The include telnet, rlogin, and rsh. SSH runs at TCP/IP port 22. This is right between ftp and telnet, which are 20 years older. Read the story of how SSH got port 22. The following video summarizes how and why SSH was originally developed.ssh
command on Unix/Linux or the Mac terminal. For general information about SSH and other implementations, see the SSH protocol home page.ssh
command. This command is used to start the SSH client program that enables secure connection to the SSH server on a remote machine. The ssh
command is used from logging into the remote machine, transferring files between the two machines, and for executing commands on the remote machine.Contents
SSH Command in Linux
ssh
command provides a secure encrypted connection between two hosts over an insecure network. This connection can also be used for terminal access, file transfers, and for tunneling other applications. Graphical X11 applications can also be run securely over SSH from a remote location.Other SSH Commands
ssh
. Each has its own page.Using the Linux client
ssh sample.ssh.com
The authenticity of host 'sample.ssh.com' cannot be established.
DSA key fingerprint is 04:48:30:31:b0:f3:5a:9b:01:9d:b3:a7:38:e2:b1:0c.
Are you sure you want to continue connecting (yes/no)?
yes
to continue. This will add the server to your list of known hosts (~/.ssh/known_hosts
) as seen in the following message:Warning: Permanently added 'sample.ssh.com' (DSA) to the list of known hosts.
Specifying a different user name
ssh [email protected]
ssh -l alternative-username sample.ssh.com
Executing remote commands on the server
ssh hostname command
ls /tmp/doc
ssh sample.ssh.com ls /tmp/doc
SSH client configuration file
ssh
command reads its configuration from the SSH client configuration file ~/.ssh/config
. For more information, see the page on SSH client configuration file.Configuring public key authentication
Configuring port forwarding
SSH command line options
[bind_address:]
port Dynamic application-level port forwarding. This allocates a socket to listen to port on the local side. When a connection is made to this port, the connection is forwarded over the secure channel, and the application protocol is then used to determine where to connect to from the remote machine.[user@]
host[:port]
Connect to the target host by first making a ssh connection to the pjump host[(/iam/jump-host) and then establishing a TCP forwarding to the ultimate destination from there.A little history
FAQs
SSH command usage, options, and configuration in Linux/Unix? ›
The ssh command is used to securely log into a remote machine and execute commands on that machine. The basic syntax of the command is “ssh user@host”, where user is the username on the remote machine and host is the address or hostname of the remote machine.
How to use SSH command in Unix? ›The ssh command is used to securely log into a remote machine and execute commands on that machine. The basic syntax of the command is “ssh user@host”, where user is the username on the remote machine and host is the address or hostname of the remote machine.
How to SSH configuration in Linux? ›- Step1: Install and enable SSH Server. ...
- Step2: Enable SSH Protocol Version 2. ...
- Step 3: Customize the default SSH port (22) ...
- Step4: Disable root login (SSH) ...
- Step 5: Use ssh keys (Public and Private) ...
- Step 6: Disable X11 Forwarding. ...
- Step 7: Disable Empty Passwords. ...
- Step 8: Set Max Authentication Attempts.
SSH Command in Linux
The ssh command provides a secure encrypted connection between two hosts over an insecure network. This connection can also be used for terminal access, file transfers, and for tunneling other applications. Graphical X11 applications can also be run securely over SSH from a remote location.
- Connect via SSH Command. Open a terminal and enter the following command: ssh @ . For example, if the IP address is 192.168. ...
- Enter Yes to Continue. When prompted with a warning message that says "The authenticity of host 'xxx' can't be established", enter "yes" to continue with the connection.
- Generate a new SSH key for WebSphere Automation by using the ssh-keygen command. $ ssh-keygen -f ~/.ssh/wsa Generating public/private rsa key pair. ...
- Copy the public key to each server by using the ssh-copy-id command. ...
- Validate that you can use SSH to communicate with that server.
You can start an SSH session in your command prompt by executing ssh user@machine and you will be prompted to enter your password. You can create a Windows Terminal profile that does this on startup by adding the commandline setting to a profile in your settings.json file inside the list of profile objects.
How do I find my SSH configuration? ›The default location of a user-specific config file is in ~/. ssh/config, whereas the system-wide configuration file for all users is in /etc/ssh/ssh_config.
How to change SSH configuration? ›- Backup the Configuration File. Before making any changes, it's always a good practice to back up your SSH configuration file.
- Edit the SSH Configuration File. ...
- Sample Output:
- Locate the Port Directive. ...
- Change the Port Number. ...
- Save and Close the File. ...
- Adjust Firewall Rules. ...
- Restart the SSH Service.
You can verify that the SSH server is running by running “ssh localhost” on the Linux side. If it asks for the key/password, the server is active: If the server is not running, you can manually start it by running “sudo service sshd start” or “sudo systemctl start sshd”.
What is SSH usage? ›
SSH or Secure Shell is a network communication protocol that enables two computers to communicate (c.f http or hypertext transfer protocol, which is the protocol used to transfer hypertext such as web pages) and share data.
How to run SSH service on Linux? ›- Open the terminal application.
- You must log in as root.
- Use the following commands to start the sshd service: /etc/init.d/sshd start. OR (for modern Linux distro with systemd) ...
- In some cases, the actual script name is different. For example, it is ssh.service on a Debian/Ubuntu Linux.
- Go to Connection -> SSH -> Tunnels.
- Type in the source port number in the Source port field.
- Type the VNC server address and port in the Destination field.
- Start the SSH session as you normally would.
- Connect to your server with a VNC client of your choice.
To use the SSH command in Linux, you typically use the format ssh username@hostname . This command allows you to establish a secure shell connection with a remote server. In this example, we're using the SSH command to connect to a remote server with the IP address 192.168. 1.1 as the user 'user'.
How to remote Linux using SSH? ›- Open the list of your servers and click on the one you need. Click the Instructions button. ...
- Open a terminal (for Linux) or a command line (for Windows) on your computer. Enter the command: ...
- The connection will prompt you for a password. Enter the password from the instructions.
There are two stages to establishing a connection – first, both the systems must agree upon encryption standards to protect future communications, and second, the user must authenticate themselves. If the credentials match, then the user is granted SSH access.
How to use SSH key command? ›- Press the Windows key or open up the Start Menu. Type “cmd”.
- Under “Best Match”, click “Command Prompt”.
- In the command prompt, use the ssh-keygen command: ...
- The system will now generate the key pair and display the key fingerprint and a randomart image. ...
- Open your file explorer.
- Open the terminal application.
- You must log in as root.
- Use the following commands to start the sshd service: /etc/init.d/sshd start. OR (for modern Linux distro with systemd) ...
- In some cases, the actual script name is different. For example, it is ssh.service on a Debian/Ubuntu Linux.
- Save it on the Desktop.
- Double click putty on the Desktop.
- In the Host Name (or IP address) field, type the remote system you intend to connect to (smpserv.hku.hk in this example).
- Select SSH under connection type.
To authenticate using SSH keys, a user must have an SSH key pair on their local computer. On the remote server, the public key must be copied to a file within the user's home directory at ~/. ssh/authorized_keys . This file contains a list of public keys, one-per-line, that are authorized to log into this account.